Last active
June 11, 2016 10:53
-
-
Save 5angel/7a89f1822a01f4d44c8353e98d6f1400 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
const STORE = {}; | |
export default { | |
init: function (name, Fn) { | |
if (typeof name !== 'undefined') { | |
return STORE[name] = Fn; | |
} | |
Fn = STORE[this.root.getAttribute('data-as')]; | |
let instance = Fn && new Fn(); | |
if (instance) { | |
let _prototype; | |
let _super = {}; | |
let mixin = _super; | |
do { // reconstruct prototype chain | |
let previous = !_prototype ? instance : _prototype; | |
_prototype = Object.getPrototypeOf(previous); | |
// skip the first & the last | |
if (previous !== instance && _prototype !== null) { | |
Object.getOwnPropertyNames(previous) | |
.forEach(function (key) { | |
if (key !== 'constructor') { | |
// skip first super | |
if (_super !== mixin && key !== 'init') { | |
_super[key] = previous[key]; | |
} | |
if (!mixin.hasOwnProperty(key)) { | |
mixin[key] = previous[key]; | |
} | |
} | |
}); | |
// we need to go super (but not too super) | |
if (Object.prototype !== _prototype) { | |
_super._super = {}; | |
_super = _super._super; | |
} | |
} | |
} while (_prototype); | |
this.mixin(mixin); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment