Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- count = 0;
- function Klacc(){
- }
- Klacc.extend = function(Child, Parent)
- {
- if (typeof Parent === 'undefined')
- Parent = Klacc;
- var F = function() { };
- F.prototype = Parent.prototype;
- Child.prototype = new F();
- Child.prototype.constructor = Child;
- Child.super = Parent.prototype;
- };
- Klacc.prototype.as = function(cl)
- {
- if ( (typeof this._as === "object") && this._as[cl] )
- {
- return this._as[cl];
- }
- var curr = this;
- while ( curr.constructor.name !== cl ) curr = curr.constructor.super;
- if ( typeof this._as === "undefined" )
- {
- this._as = {};
- }
- else if ( typeof this._as !== "object")
- {
- throw { context:this, message:"object already has reserved property \"_as\" invalid type" }
- }
- this._as[cl] = curr;
- return curr;
- }
- Klacc.prototype.parentOf = function(cl)
- {
- var curr = this.as(cl);
- return curr.constructor.super;
- }
- function A() { }
- Klacc.extend(A)
- A.prototype.init = function(){ /* A.prototype.init */
- if (++count < 100)
- console.log('A.prototype.init.apply', this);
- this.name = 'A';
- }
- function B(){ }
- Klacc.extend(B,A)
- B.prototype.init = function(){ /* B.prototype.init; this - instance of D */
- if (++count < 100)
- console.log('B.prototype.init.apply', this);
- console.log('Parent Of B', this.parentOf('B'));
- this.parentOf('B').init.apply(this,arguments);
- this.extra = 'im B';
- }
- function C() { }
- Klacc.extend(C,B)
- C.prototype.init = function(){ /* C.prototype.init; this - instance of D */
- if (++count < 100)
- console.log('C.prototype.init.apply', this);
- console.log('Parent Of C', this.parentOf('C'))
- this.parentOf('C').init.apply(this,arguments);
- this.extraC = 'mimimi';
- }
- c= new C
- function D() { }
- Klacc.extend(D,C)
- D.prototype.init = function(){ /* D.prototype.init */
- if (++count < 100)
- console.log('D.prototype.init.apply', this);
- console.log('Parent Of D', this.parentOf('D'))
- this.parentOf('D').init.apply(this,arguments);
- }
- d = new D
- d.init()
Advertisement
Add Comment
Please, Sign In to add comment