Skip to content

Instantly share code, notes, and snippets.

@brownsmith
Created May 29, 2018 07:28
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save brownsmith/ff5dab188c9a06348398ba93757089e7 to your computer and use it in GitHub Desktop.
Save brownsmith/ff5dab188c9a06348398ba93757089e7 to your computer and use it in GitHub Desktop.
Classes and composition
// ##### CLASS INHERITANCE:
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;
}
}
const guitaramp = new GuitarAmp();
const bassamp = new BassAmp();
const channelstrip = new ChannelStrip();
console.log('guitaramp', guitaramp);
console.log('bassamp', bassamp);
console.log('channel', channelstrip);
// ##### COMPOSITION EXAMPLE:
const distortion = { distortion: 1 };
const volume = { volume: 1 };
const cabinet = { cabinet: 'maple' };
const lowCut = { lowCut: 1 };
const inputLevel = { inputLevel: 1 };
const GuitarAmpComp = (options) => {
return Object.assign({}, distortion, volume, cabinet, options);
};
const BassAmpComp = (options) => {
return Object.assign({volume: 2}, lowCut, cabinet, options);
};
const ChannelStripComp = (options) => {
return Object.assign({}, inputLevel, lowCut, volume, options);
};
const guitarampcomp = GuitarAmpComp();
const bassampcomp = BassAmpComp();
const channelstripcomp = ChannelStripComp();
console.log('guitarampcomp', guitarampcomp);
console.log('bassampcomp', bassampcomp);
console.log('channelstripcomp', channelstripcomp);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment