Skip to content

Instantly share code, notes, and snippets.

@tothandras
Created December 31, 2017 12:57
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save tothandras/ead48e5d4ab9e61c8ae07c660241e32e to your computer and use it in GitHub Desktop.
Save tothandras/ead48e5d4ab9e61c8ae07c660241e32e to your computer and use it in GitHub Desktop.
Node.js DI
// a/a.js
class A {
constructor(b) {
this.b = b
}
foo() {
this.b.bar()
}
}
module.exports = A
// b/b.js
class B {
bar() {
console.log('hello')
}
}
module.exports = B
// a/index.js
const b = require('../b')
const A = require('./a')
module.exports = new A(b)
// b/index.js
const B = require('./b')
module.exports = new B()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment