Skip to content

Instantly share code, notes, and snippets.

@fattenap
Forked from sebmarkbage/es6mixin.js
Last active August 29, 2015 14:16
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 fattenap/2c2693edf048ae563fe8 to your computer and use it in GitHub Desktop.
Save fattenap/2c2693edf048ae563fe8 to your computer and use it in GitHub Desktop.
var Bar1 = base => class extends base {
componentWillMount(){
super.componentWillMount();
console.log('Bar1');
}
};
var Bar2 = base => class extends base {
componentWillMount(){
super.componentWillMount();
console.log('Bar2');
}
};
class Foo extends mixins(Bar1, Bar2) {
componentWillMount() {
console.log('Foo before mixins');
super.componentWillMount();
console.log('Foo after mixins');
}
}
function mixins(...mixinFactories) {
var base = class {};
// TODO: Add all possible method names that might call super()
// to the base class so that they don't throw.
for (var i = 0; i < mixinFactories.length; i++) {
base = mixinFactories[i](base);
}
return base;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment