summaryrefslogtreecommitdiffhomepage
path: root/javascript.html.markdown
diff options
context:
space:
mode:
authorAdam Brenecki <adam@brenecki.id.au>2013-09-20 19:22:00 +0930
committerAdam Brenecki <adam@brenecki.id.au>2013-09-20 19:22:00 +0930
commit750b2a2f21262fc011d5ee07362c667223d3de23 (patch)
tree060618177794a1bea9b5bf910ac9e5e6f6e20dd1 /javascript.html.markdown
parent49b30c38e2741162bd1661e020fe80c80759dee3 (diff)
[javascript] clarify constructor prototype example, as per #204
Diffstat (limited to 'javascript.html.markdown')
-rw-r--r--javascript.html.markdown3
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.