1
0
mirror of https://github.com/adambard/learnxinyminutes-docs.git synced 2025-08-06 23:06:49 +02:00

[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 // 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. // are given when they're created with that constructor and the new keyword.
myConstructor.prototype = { myConstructor.prototype = {
myNumber: 5,
getMyNumber: function(){ getMyNumber: function(){
return this.myNumber; return this.myNumber;
} }
}; };
var myNewObj2 = new myConstructor(); var myNewObj2 = new myConstructor();
myNewObj2.getMyNumber(); // = 5 myNewObj2.getMyNumber(); // = 5
myNewObj2.myNumber = 6
myNewObj2.getMyNumber(); // = 6
// Built-in types like strings and numbers also have constructors that create // Built-in types like strings and numbers also have constructors that create
// equivalent wrapper objects. // equivalent wrapper objects.