Created
May 11, 2011 23:00
-
-
Save unscriptable/967587 to your computer and use it in GitHub Desktop.
IOC/DI as an alternative to module swapping
This file contains 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
// admittedly, dependency injection is better for non-integral dependencies. | |
// integral dependencies like coding constructs such as array iterators (forEach), | |
// type detectors (isArray, isFunction), etc are easier to work with as declared | |
// dependencies/modules. there are other ways to inject dependencies (e.g. | |
// constructor params). this is just how we're doing it. | |
// this example shows the injection of non-integral dependencies | |
define(function () { | |
return { | |
// templateEngine must be injected by controller or ioc container | |
templateEngine: null, | |
// template must be injected by controller or ioc container | |
template: null, | |
// do something with injected dependencies | |
render: function (domNode) { | |
var view; | |
view = this.templateEngine(this.template); | |
domNode.appendChild(view); | |
} | |
}; | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment