Skip to content

Instantly share code, notes, and snippets.

@indexzero
Created June 22, 2017 20:14
Show Gist options
  • Save indexzero/3ae7abce662d2eaafe086b186fcabbcc to your computer and use it in GitHub Desktop.
Save indexzero/3ae7abce662d2eaafe086b186fcabbcc to your computer and use it in GitHub Desktop.
Use static class methods in ES6 to perform lightweight dependency injection / IOC
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