Skip to content

Instantly share code, notes, and snippets.

@halcarleton
Last active October 17, 2016 18:58
Show Gist options
  • Select an option

  • Save halcarleton/0cb305ab804e8159b86ecf8b2448ad02 to your computer and use it in GitHub Desktop.

Select an option

Save halcarleton/0cb305ab804e8159b86ecf8b2448ad02 to your computer and use it in GitHub Desktop.

Revisions

  1. halcarleton revised this gist Oct 17, 2016. 1 changed file with 2 additions and 2 deletions.
    4 changes: 2 additions & 2 deletions SuperConstructor.js
    Original file line number Diff line number Diff line change
    @@ -19,8 +19,8 @@ function SubOne(p1) {
    delete this.y.a;
    };

    SubOne.prototype = new Base();
    SubOne.constructor = SubOne;
    SubOne.prototype = Object.create(Base.prototype);
    SubOne.prototype.constructor = SubOne;

    /**
    * new Base(2, 3) == {
  2. halcarleton revised this gist Oct 17, 2016. 1 changed file with 2 additions and 0 deletions.
    2 changes: 2 additions & 0 deletions SuperConstructor.js
    Original file line number Diff line number Diff line change
    @@ -1,3 +1,4 @@
    // Base Class
    function Base(p1, p2) {
    this.x = this.someMethod(p1, p2);
    this.y = {
    @@ -12,6 +13,7 @@ Base.prototype.someMethod = funciotn(a, b) {

    /*************/

    // SubClass that inherits from Base
    function SubOne(p1) {
    Base.call(this, 10, p1);
    delete this.y.a;
  3. halcarleton created this gist Jun 20, 2016.
    40 changes: 40 additions & 0 deletions SuperConstructor.js
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,40 @@
    function Base(p1, p2) {
    this.x = this.someMethod(p1, p2);
    this.y = {
    a: p1,
    b: p2
    };
    }

    Base.prototype.someMethod = funciotn(a, b) {
    return a + b;
    };

    /*************/

    function SubOne(p1) {
    Base.call(this, 10, p1);
    delete this.y.a;
    };

    SubOne.prototype = new Base();
    SubOne.constructor = SubOne;

    /**
    * new Base(2, 3) == {
    * someMethod: Base.prototype.someMethod,
    * x: 5,
    * y: {
    * a: 2,
    * b: 3
    * }
    * }
    *
    * new SubOne(8) == {
    * someMethod: Base.prototype.someMethod,
    * x: 80,
    * y: {
    * b: 8
    * }
    * }
    */