Skip to content

Instantly share code, notes, and snippets.

@mpj
Last active September 4, 2017 14:48
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 mpj/8c20ed273e8a0331958f69b827c77741 to your computer and use it in GitHub Desktop.
Save mpj/8c20ed273e8a0331958f69b827c77741 to your computer and use it in GitHub Desktop.
di example
let createGetUserName = require('./di-lib.js')
const getUsername = createGetUserName(database)
getUserName(1).then(name => console.log('the name of user 1 is', name))
// notice: no require statement!
function createGetUserName(database) {
return function getUserName(id) {
return db.table('users').load(id)
.then(user => user.name)
}
}
module.exports = createGetUserName
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment