簡単な継承メカニズムを実装できます。
var Class = function( parent ){
var f = function(){};
if( typeof parent == 'function' ){
f.prototype = new parent;
}else if( parent) {
f.prototype = parent;
}
f.prototype.__parent = parent; // :)
f.prototype.__root = ( parent && parent.prototype && parent.prototype.__root) || parent || f; // :)
return f
};
そしていま:
var A = Class(),
B = Class(A),
C = Class(B),
objA = new A,
objB = new B,
objC = new C;
objC.__parent == B; // true;
objB.__parent == A; // true
(objC.__root == objB.__root) && ( objA.__root == A ); // true;
ただし、ルートオブジェクトのプロトタイプを特定できます(あなたの場合):
var A = Class({
nw: function( t ) {
// What you like here? :)
return new t( this.__parent );
//return new t( this.constructor );
//return new t( this.__root );
}
});