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:
@@ -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.
|
||||||
|
Reference in New Issue
Block a user