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'));