From 750b2a2f21262fc011d5ee07362c667223d3de23 Mon Sep 17 00:00:00 2001 From: Adam Brenecki Date: Fri, 20 Sep 2013 19:22:00 +0930 Subject: [javascript] clarify constructor prototype example, as per #204 --- javascript.html.markdown | 3 +++ 1 file changed, 3 insertions(+) (limited to 'javascript.html.markdown') 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. -- cgit v1.2.3