SwVitaliy

problem2

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