Last active
April 21, 2020 13:54
-
-
Save ericelliott/b668ce0ad1ab540df915 to your computer and use it in GitHub Desktop.
Class Inheritance Example http://codepen.io/ericelliott/pen/pgdPOb?editors=001
This file contains 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 characters
// 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 { | |
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(); | |
}); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment