[javascript] clarify constructor prototype example, as per #204

This commit is contained in:
Adam Brenecki 2013-09-20 19:22:00 +09:30
parent 49b30c38e2
commit 750b2a2f21

View File

@ -358,12 +358,15 @@ myObj.meaningOfLife; // = 43
// the constructor function itself; instead, it's the prototype that new objects
// are given when they're created with that constructor and the new keyword.
myConstructor.prototype = {
myNumber: 5,
getMyNumber: function(){
return this.myNumber;
}
};
var myNewObj2 = new myConstructor();
myNewObj2.getMyNumber(); // = 5
myNewObj2.myNumber = 6
myNewObj2.getMyNumber(); // = 6
// Built-in types like strings and numbers also have constructors that create
// equivalent wrapper objects.