Created
October 24, 2017 19:02
-
-
Save march213/19e2f6a3487ec976da2ee9a2cbe04d82 to your computer and use it in GitHub Desktop.
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
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