Created
January 8, 2013 12:20
-
-
Save benqus/4483318 to your computer and use it in GitHub Desktop.
Revisions
-
Bence created this gist
Jan 8, 2013 .There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,58 @@ var prototypeTest = (function () { /** * Instance class definition * inherits from Base */ function Instance() { //super class constructor Base.apply(this, arguments); } /** * Base class definition */ function Base(name) { var privates = { 'name': name }; this.getPrivate = function (name) { return privates[name]; }; } /** * prorotype function */ Base.prototype.get = function () { return this.getPrivate.apply(this, arguments); }; /** * resolving inheritance in the scope */ Instance.prototype = Base.prototype; /** * exposing 2 instances */ return { i: new Instance('Geri'), j: new Instance('Benő') }; }()); /** * short logging to check behaviour */ console.log(Object.getPrototypeOf(prototypeTest.i)); console.log(Object.getPrototypeOf(prototypeTest.i).set = function () {}); console.log(Object.getPrototypeOf(prototypeTest.i) === Object.getPrototypeOf(prototypeTest.j)); console.log(Object.getPrototypeOf(prototypeTest.j)); console.log(Object.getPrototypeOf(prototypeTest.i)); console.log(prototypeTest); console.log(prototypeTest.i.get('name')); console.log(prototypeTest.j.get('name'));