Skip to content

Instantly share code, notes, and snippets.

@ericelliott
Last active April 21, 2020 13:54
Show Gist options
  • Save ericelliott/b668ce0ad1ab540df915 to your computer and use it in GitHub Desktop.
Save ericelliott/b668ce0ad1ab540df915 to your computer and use it in GitHub Desktop.
// 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