Last active
May 3, 2016 10:07
-
-
Save evolutionxbox/d118a5a5ac6694638700 to your computer and use it in GitHub Desktop.
Compositional Inheritance using ES2015 classes
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 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