Skip to content

Instantly share code, notes, and snippets.

@march213
Created October 24, 2017 19:02
Show Gist options
  • Save march213/19e2f6a3487ec976da2ee9a2cbe04d82 to your computer and use it in GitHub Desktop.
Save march213/19e2f6a3487ec976da2ee9a2cbe04d82 to your computer and use it in GitHub Desktop.
var T2 = (()=>{
// todo: mixins collection
class Foo {
foo () {
this.__super();
console.log(this.bar());
}
bar() {console.log('bar')}
}
const SomeMixin = { foo: function () {console.log('mixin')} }
function mixinIt (Target, mixin) {
class Target_ extends Target {}
Object.keys(mixin).forEach((prop) => {
if (typeof Target.prototype[prop] === 'function') {
const oldMethod = Target.prototype[prop];
Target_.prototype[prop] = function (...args) {
debugger
const newThis = Object.assign({},this,{__super: oldMethod });
debugger;
return mixin[prop].apply(newThis, args)
};
} else {
Target_.prototype[prop] = mixin[prop];
}
})
return Target_;
}
return mixinIt(Foo, SomeMixin)
// copy statics
})()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment