IMPORTANT: Per accedir als fitxer de subversion: http://acacha.org/svn (sense password). Poc a poc s'aniran migrant els enllaços. Encara però funciona el subversion de la farga però no se sap fins quan... (usuari: prova i la paraula de pas 123456)

Exemple

NodeJS, CommonJS, AMD

CommonJS and AMD actually both implements the same design pattern named service locator, in service locator developers call the require or define function to ask explicitly for the dependency from the locator, the locator then feeds the dependency module back, this pattern is simple and easy. Dependency injection, however on the other end, components do not look up, they provide plain simple configuration metadata enabling the container to resolve dependencies. The container is wholly responsible for wiring up components, passing resolved objects into JavaScript Object properties or constructors. Hence the inversion of control.

Service locator and dependency injection are both ways to resolve dependencies and enable modular codes, there is no golden rule on which is better, it all depends. Basically, when you write to quick and easy development, like library、 shell、 tools, you may choose to use service locator. When you want to write project that needed be continuously maintainable, you may choose to use dependency injection. What’s more, service locator and dependency injection can be used together to take advantages of both.

From:

http://bearcatjs.org/2015/01/02/browserify-with-asynchronous-script-loading/

Vegeu també

Enllaços externs