One of the advantages of using the object literal constructor (your code), which has not yet been specified, is that when creating a new instance of the object, the new keyword is not required. Or, in other words, if you just forget to use the new keyword, your code will still work the way you plan, since you no longer rely on the use of the new keyword to provide the this scope of your newly created object in your constructor function ; An object that now takes care of you.
This is the approach that the YUI library (and Douglas Crockford) uses for designers.
Consider the following simple constructor:
var Car = function(model){ this.model = model; };
If you were to call Car('Dodge Viper'); or even var MyCar = Car('Dodge Viper'); , this in the function actually refers to the global window object. So now the Model property is actually a global variable, which is probably not what it was intended to be.
var Car = function(model) { var that = {}; that.model = model; return that; };
source share