Last active
March 22, 2017 09:52
-
-
Save cbrunnkvist/d36c2dc7253e55e458b2af7ed5e674b8 to your computer and use it in GitHub Desktop.
ES6 composition: mixins / traits using anonymous subclass factories
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 Fig { constructor() { console.log("I'm Ficus carica") } } | |
const Dateable = (SC) => class extends SC { constructor() { super(); this.creationDate = new Date() } } | |
const Invisible = (SC) => class extends SC { isVisible() { return false } } | |
class InvisibleDateableFig extends Invisible(Dateable(Fig)) {} | |
let f = new InvisibleDateableFig() | |
// > f | |
// InvisibleDateableFig { creationDate: 2017-01-26T04:28:32.313Z } | |
// > f instanceof Fig | |
// true | |
// > f.isVisible() | |
// false |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment