Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Select an option

  • Save Elemino/095d3150df2e2f77b12c61664b4436b4 to your computer and use it in GitHub Desktop.

Select an option

Save Elemino/095d3150df2e2f77b12c61664b4436b4 to your computer and use it in GitHub Desktop.

Revisions

  1. @ericelliott ericelliott revised this gist Jan 19, 2016. 1 changed file with 2 additions and 0 deletions.
    2 changes: 2 additions & 0 deletions class-inheritance-example.js
    Original file line number Diff line number Diff line change
    @@ -1,5 +1,7 @@
    // Class Inheritance Example
    // NOT RECOMMENDED. Use object composition, instead.

    // https://gist.github.com/ericelliott/b668ce0ad1ab540df915
    // http://codepen.io/ericelliott/pen/pgdPOb?editors=001

    class GuitarAmp {
  2. @ericelliott ericelliott created this gist Jan 19, 2016.
    49 changes: 49 additions & 0 deletions class-inheritance-example.js
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,49 @@
    // Class Inheritance Example
    // NOT RECOMMENDED. Use object composition, instead.
    // http://codepen.io/ericelliott/pen/pgdPOb?editors=001

    class GuitarAmp {
    constructor ({ cabinet = 'spruce', distortion = '1', volume = '0' } = {}) {
    Object.assign(this, {
    cabinet, distortion, volume
    });
    }
    }

    class BassAmp extends GuitarAmp {
    constructor (options = {}) {
    super(options);
    this.lowCut = options.lowCut;
    }
    }

    class ChannelStrip extends BassAmp {
    constructor (options = {}) {
    super(options);
    this.inputLevel = options.inputLevel;
    }
    }

    test('Class Inheritance', nest => {
    nest.test('BassAmp', assert => {
    const msg = `instance should inherit props
    from GuitarAmp and BassAmp`;

    const myAmp = new BassAmp();
    const actual = Object.keys(myAmp);
    const expected = ['cabinet', 'distortion', 'volume', 'lowCut'];

    assert.deepEqual(actual, expected, msg);
    assert.end();
    });

    nest.test('ChannelStrip', assert => {
    const msg = 'instance should inherit from GuitarAmp, BassAmp, and ChannelStrip';
    const myStrip = new ChannelStrip();
    const actual = Object.keys(myStrip);
    const expected = ['cabinet', 'distortion', 'volume', 'lowCut', 'inputLevel'];

    assert.deepEqual(actual, expected, msg);
    assert.end();
    });
    });