Skip to content

Instantly share code, notes, and snippets.

@evolutionxbox
Last active May 3, 2016 10:07
Show Gist options
  • Save evolutionxbox/d118a5a5ac6694638700 to your computer and use it in GitHub Desktop.
Save evolutionxbox/d118a5a5ac6694638700 to your computer and use it in GitHub Desktop.
Compositional Inheritance using ES2015 classes
class Openable {
constructor(isOpen = false) {
this._isOpen = isOpen;
}
get isOpen() {
return this._isOpen + ' is stupid.';
}
set isOpen(value) {
this._isOpen = value;
}
}
class Hideable {
constructor(isHidden = false) {
this._isHidden = isHidden;
}
get isHidden() {
return this._isHidden + ' is stupid.';
}
set isOpen(value) {
this._isHidden = value;
}
}
class Thing {
constructor(config) {
let { isOpen, isHidden } = config;
let openable = new Openable(isOpen);
this.isOpen = openable.isOpen;
let hideable = new Hideable(isHidden);
this.isHidden = openable.isHidden;
}
}
let thing = new Thing({
isOpen: true,
isHidden: false
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment