Skip to content

Instantly share code, notes, and snippets.

@scribblet
Created December 27, 2013 10:01
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 scribblet/8144836 to your computer and use it in GitHub Desktop.
Save scribblet/8144836 to your computer and use it in GitHub Desktop.
Closure form of DI
//makeThumbnail.js
module.exports = function(db) {
db = db || require('./database.js');
return {
start : function(input){
// makeThumbnail
// save timestamp
db.save({...});
}
};
//and it would be used like this in taskRunner.js and tests:
var db = require('./database.js'),
makeThumbnail = require('./tasks/makeThumbnail')(db);
//End usage won't be cluttered with dependency injection with this.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment