Advertisement
Guest User

Inheritance Model

a guest
Mar 5th, 2013
90
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. //Helper function to 'extend' prototypes
  2. var __extends = this.__extends || function (d, b) {
  3.     function __() { this.constructor = d; }
  4.     __.prototype = b.prototype;
  5.     d.prototype = new __();
  6. };
  7.  
  8. //Base class with a single function defined
  9. var BaseClass = (function () {
  10.     function BaseClass() { }
  11.     BaseClass.prototype.calc = function (x, y) {
  12.     };
  13.     return BaseClass;
  14. })();
  15.  
  16. //Child class with the function overwritten.
  17. //It calls the base class function in the
  18. //context of 'this', so the base class
  19. //function can actually access members of
  20. //the child class when called.
  21. var ChildClass = (function (_super) {
  22.     __extends(ChildClass, _super);
  23.     function ChildClass() {
  24.         _super.apply(this, arguments);
  25.  
  26.     }
  27.     ChildClass.prototype.calc = function (x, y) {
  28.         var z = _super.prototype.calc.call(this, x, y);
  29.     };
  30.     return ChildClass;
  31. })(BaseClass); //Notice the base class 'inheritance'
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement