SwVitaliy

Untitled

May 16th, 2012
65
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. count = 0;
  2. function Klacc(){
  3. }
  4. Klacc.extend = function(Child, Parent)
  5.     {
  6.  
  7. if (typeof Parent === 'undefined')
  8.     Parent = Klacc;
  9.  
  10.         var F = function() { };
  11.         F.prototype = Parent.prototype;
  12.         Child.prototype = new F();
  13.         Child.prototype.constructor = Child;
  14.  
  15. Child._as = {};
  16. if ( typeof Parent._as === 'object' ) {
  17.  
  18. var i;
  19. for(i in Parent._as)
  20. {
  21.    Child._as[i] = Parent._as[i];
  22. }
  23. Child._as[Parent.name] = Parent.prototype;
  24. }
  25.  
  26.         Child.super = Parent.prototype;
  27.     };
  28.  
  29. Klacc.prototype.as = function(cl)
  30. {
  31. var cl = typeof cl === "function" ? cl.name : cl;
  32. var ctor = this.constructor;
  33. if ( ctor.name === cl )
  34. {
  35.   return this;
  36. }
  37. else if ( (typeof ctor._as === "object") && ctor._as[cl] )
  38. {
  39.   return ctor._as[cl];
  40. }
  41. return false;
  42.  
  43. }
  44. Klacc.prototype.parentOf = function(cl)
  45. {
  46.   return this.as(cl).constructor.super;
  47. }
  48.  
  49. function A() {  }
  50. Klacc.extend(A)
  51. A.prototype.init = function(){ /* A.prototype.init */
  52.   if (++count < 100)
  53.     console.log('A.prototype.init.apply', this);
  54.   this.name = 'A';
  55. }
  56.  
  57.  
  58. function B(){  }
  59. Klacc.extend(B,A)
  60. B.prototype.init = function(){ /* B.prototype.init; this - instance of D */
  61.   if (++count < 100)
  62.     console.log('B.prototype.init.apply', this);
  63. console.log('Parent Of B', this.parentOf(B));
  64. this.parentOf(B).init.apply(this,arguments);
  65.  
  66.   this.extra = 'im B';
  67. }
  68.  
  69. function C() {  }
  70. Klacc.extend(C,B)
  71. C.prototype.init = function(){ /* C.prototype.init; this - instance of D */
  72.   if (++count < 100)
  73.     console.log('C.prototype.init.apply', this);
  74.  
  75. console.log('Parent Of C', this.parentOf(C))
  76.     this.parentOf(C).init.apply(this,arguments);
  77.  
  78.   this.extraC = 'mimimi';
  79. }
  80. c= new C
  81.  
  82. function D() {  }
  83.  
  84. Klacc.extend(D,C)
  85.  
  86. D.prototype.init = function(){ /* D.prototype.init */
  87.   if (++count < 100)
  88.     console.log('D.prototype.init.apply', this);
  89. console.log('Parent Of D', this.parentOf('ags'));return;
  90.     this.parentOf('D').init.apply(this,arguments);
  91.  
  92. }
  93.  
  94. d = new D
  95.  
  96. d.init()
Advertisement
Add Comment
Please, Sign In to add comment