SwVitaliy

Untitled

May 11th, 2012
64
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. extend = function(Child, Parent)
  2.         {
  3.         var F = function() { };
  4.         F.prototype = Parent.prototype;
  5.         Child.prototype = new F();
  6.         Child.prototype.constructor = Child;
  7.         Child.super = Parent.prototype;
  8.     };
  9. >function (Child, Parent)
  10. >        {
  11. >        var F = function() { };
  12. >        F.prototype = Parent.prototype;
  13. >        Child.prototype = new F();
  14. >        Child.prototype.constructor = Child;
  15. >        Child.super = Parent.prototype;
  16. >    }
  17. function A() {  }
  18. >undefined
  19. A.prototype.init = function(){this.name = 'A'}
  20. >function (){this.name = 'A'}
  21. function B(){  }
  22. >undefined
  23. extend(B, A)
  24. >undefined
  25. count = 0;
  26. >0
  27. B.prototype.init = function(){ if (++count < 100) console.log('B.prototype.init.apply', this); this.constructor.super.init.apply(this,arguments); this.extra = 'im B';}
  28. >function (){ if (++b < 100) console.log('B.prototype.init.apply', this); this.constructor.super.init.apply(this,arguments); this.extra = 'im B';}
  29. function C() {  }
  30. >undefined
  31. extend(C, B)
  32. >undefined
  33. C.prototype.init = function(){  if (++count < 100) console.log('C.prototype.init.apply', this); this.constructor.super.init.apply(this,arguments); this.extraC = 'mimimi';}
  34. >function (){  if (++count < 100) console.log('C.prototype.init.apply', this); this.constructor.super.init.apply(this,arguments); this.extraC = 'mimimi';}
  35. (new C).init()
  36. >C.prototype.init.apply
  37. >C
  38. >B.prototype.init.apply
  39. >C
  40. >B.prototype.init.apply
  41. >C
  42. >B.prototype.init.apply
  43. >C
  44. >B.prototype.init.apply
  45. >C
  46. >B.prototype.init.apply
  47. >C
  48. >B.prototype.init.apply
  49. >C
  50. >B.prototype.init.apply
  51. >C
  52. >B.prototype.init.apply
  53. >C
  54. ...
  55. >RangeError: Maximum call stack size exceeded
  56. >  arguments: Array[0]
  57. >  get message: function getter() { [native code] }
  58. >  set message: function setter() { [native code] }
  59. >  stack: undefined
  60. >  type: "stack_overflow"
  61. >    __proto__: Error
Advertisement
Add Comment
Please, Sign In to add comment