So, when we create constructor function for creating new object the new keyword does 3 things I\'am going to explain it but please correct me if I\'am wrong i want to be sur
In this example, during constructor invocation, obj1
is undefined. Value is assigned to obj1
variable after ObjectCreate
function returns.
You can check yourself:
function ObjectCreate(){
this.a = "a";
this.b = "b";
alert(obj1); // yields "undefined"
ObjectCreate.prototype.show = function(){
alert(this.a+" "+this.b);
}
}
var obj1 = new ObjectCreate(); // note "var"