Created
June 22, 2017 20:14
-
-
Save indexzero/3ae7abce662d2eaafe086b186fcabbcc to your computer and use it in GitHub Desktop.
Use static class methods in ES6 to perform lightweight dependency injection / IOC
This file contains hidden or 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 Injector { | |
static register(key) { | |
this.Components = this.Components || {}; | |
this.Components[key] = key; | |
console.log(this.Components); | |
} | |
passthru(key) { | |
Injector.register(key); | |
} | |
} | |
Injector.register('foo'); | |
const inst = new Injector(); | |
inst.passthru('bar'); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment