Created
February 9, 2013 03:43
-
-
Save liammclennan/4743734 to your computer and use it in GitHub Desktop.
Node.js dependency injection
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
| var declaration = require('./declaration'); | |
| declaration(); | |
| // --> assertion error 3 is not equal to 4 | |
| declaration({ | |
| assert: { | |
| equal: function () { | |
| return true; | |
| } | |
| } | |
| }); | |
| // --> |
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
| function resolve(deps, name) { | |
| if (deps && deps[name]) { | |
| return deps[name]; | |
| } else { | |
| return require(name); | |
| } | |
| } | |
| module.exports = function(deps) { | |
| var assert = resolve(deps, 'assert'); | |
| assert.equal(3,4); | |
| }; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment