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._as = {};
- if ( typeof Parent._as === 'object' ) {
- var i;
- for(i in Parent._as)
- {
- Child._as[i] = Parent._as[i];
- }
- Child._as[Parent.name] = Parent.prototype;
- }
- Child.super = Parent.prototype;
- };
- Klacc.prototype.as = function(cl)
- {
- var cl = typeof cl === "function" ? cl.name : cl;
- var ctor = this.constructor;
- if ( ctor.name === cl )
- {
- return this;
- }
- else if ( (typeof ctor._as === "object") && ctor._as[cl] )
- {
- return ctor._as[cl];
- }
- return false;
- }
- Klacc.prototype.parentOf = function(cl)
- {
- return this.as(cl).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('ags'));return;
- this.parentOf('D').init.apply(this,arguments);
- }
- d = new D
- d.init()
Advertisement
Add Comment
Please, Sign In to add comment