Created
May 29, 2018 07:28
-
-
Save brownsmith/ff5dab188c9a06348398ba93757089e7 to your computer and use it in GitHub Desktop.
Classes and composition
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: | |
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