Possible Duplicate:
Difference between knockout View Models declared as object literals vs functions
I am working in Knowckout MVVM framework and I am new to it. I have been using it for last one and a half months and it has been decent so far. Now, all the examples that I saw on the web and everywhere else define viewmodel as something like a Object variable with a declaration like below:
var ViewModel = {};
that was comletely understandable.BUT
lately I have seen some codemodels in which it is declared as a function:
somehting like
var ViewModel = function(){
self = this;
// some code in conventions with var member = {} instead of member:{}
}
Not only that, when the view model is actually used, they have to instantiate the viewmodel.
I see it as complete new way to represent viewmodel and I am failing to see how it is better than conventional ViewModel declaration approach.
Can someone please throw some light on this?
This answer explains the difference betweeen using an object literal and a function for defining a view model: Difference between knockout View Models declared as object literals vs functions