Friday, 13 September 2013

javascript oop. Constructor vs prototyping

javascript oop. Constructor vs prototyping

I can understand what is the difference in creating and object as a
constructor and creating an object in a literal notation and when is
better to use each definition, but I can not understand the difference
between the following two cases:
function Obj(){
this.foo = function(){...}
}
function Obj(){}
Obj.prototype.foo = function(){...}
Both are doing the same thing. Both will be instantiated using the same
var objNew = new obj();
So what is the difference and when to use each concept?

No comments:

Post a Comment