I solved this question like this:
(function (exports) { /* * sample prototype, * * inherit @boolean if true - return privates object, * */ function A(inherit) { var privates = { //setup private vars, they could be also changed, added in method or children a: 1, b: 2, c: 3 }; //setup public methods which uses privates this.aPlus = bindPlus("aPlus", this, privates); //pass method name as string! this.aGet = bindPlus("aGet", this, privates); if (inherit) { return privates; } } A.prototype.aPlus = function () { var args = getArgs(arguments), //self is "this" here (applied/called too), object reference is still this privates = args.shift(), self = args.shift(), //function real arguments n = args.shift(); return privates.a += n; }; A.prototype.aGet = function (n) { var args = getArgs(arguments), privates = args.shift(), self = args.shift(); console.error(this, self,privates); return privates.a; }; exports.A = A; exports.getArgs = getArgs; //should be hidden somehow, but this is out of the story exports.bindPlus = bindPlus; //utilites function getArgs(arg) { return Array.prototype.slice.call(arg); } //вот здесь в общем-то ядро идеи function bindPlus(funct, self, privates) { /** * if uncomment here and comment same line later, * it will be run faster, but it would be impossible * to change prototype after constructor run (tests after ----- could be incorrect) */ //var func=Object.getPrototypeOf(self)[funct].bind(self, privates); return function () { var func=Object.getPrototypeOf(self)[funct].bind(self, privates); var args=getArgs(arguments); //this could be changed to speedup, but need to change method itself args.unshift(this); //called/applied this return func.apply(null, args); }; } })(this); //inherited function B(inherit) { var privates = Object.getPrototypeOf(this).constructor.call(this, true); privates.d = 4; this.dGet = bindPlus("dGet", this, privates); if (inherit) { return privates; } } B.prototype = Object.create(A.prototype); B.constructor = B; B.prototype.aGet = function () { var args = getArgs(arguments); var privates = args.shift(), self = args.shift(); console.warn("B.aGet",self, privates); return privates.a; }; B.prototype.dGet = function () { var args = getArgs(arguments), privates = args.shift(); self = args.shift(), console.warn("B.dGet", self, privates); return privates.d; };
but it is a little slow and uncomfortable, I could not find a better way to work.
http://jsfiddle.net/oceog/TJH9Q/