diff options
author | Adam Brenecki <adam@brenecki.id.au> | 2013-09-20 19:22:00 +0930 |
---|---|---|
committer | Adam Brenecki <adam@brenecki.id.au> | 2013-09-20 19:22:00 +0930 |
commit | 750b2a2f21262fc011d5ee07362c667223d3de23 (patch) | |
tree | 060618177794a1bea9b5bf910ac9e5e6f6e20dd1 | |
parent | 49b30c38e2741162bd1661e020fe80c80759dee3 (diff) |
[javascript] clarify constructor prototype example, as per #204
-rw-r--r-- | javascript.html.markdown | 3 |
1 files changed, 3 insertions, 0 deletions
diff --git a/javascript.html.markdown b/javascript.html.markdown index 9adc0a6d..b15eae7c 100644 --- a/javascript.html.markdown +++ b/javascript.html.markdown @@ -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. |