mirror of
https://github.com/adambard/learnxinyminutes-docs.git
synced 2024-12-23 09:41:36 +00:00
[javascript] clarify constructor prototype example, as per #204
This commit is contained in:
parent
49b30c38e2
commit
750b2a2f21
@ -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.
|
||||
|
Loading…
Reference in New Issue
Block a user