Forked from ericelliott/class-inheritance-example.js
Created
January 9, 2019 12:19
-
-
Save Elemino/095d3150df2e2f77b12c61664b4436b4 to your computer and use it in GitHub Desktop.
Revisions
-
ericelliott revised this gist
Jan 19, 2016 . 1 changed file with 2 additions and 0 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal 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 { -
ericelliott created this gist
Jan 19, 2016 .There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal 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(); }); });