|
|
|
|
|
by camus
4650 days ago
|
|
Module system =/= Dependency injection.
AngularJS modules =/= CommonJS modules
Module system = way to FIND object definitions physically(files) or logically(name). Python has one, NodeJS has one.Dependency injection = way to WRITE objects by creating
dependencies between them in order to separate concerns. RequireJS = gives Javascript a module system
( fetching files according to the module name to
find module definitions ),which is
configurable since JS doesnt have one.
AngularJS = instanciate objects according to their
defintion and the definition of its dependencies =>
doesnt look for files in a path to find the definitons.
And ES6 definetly DOESNT DO dependency injection, ES6 gives JS a module system which is configurable.When ES6 gets it's module system , people wont need require JS anymore, but it has nothing to do with AngularJS. |
|
- Nowhere in my post did I say a module system was dependency injection
- Nowhere in my post did I say angular JS modules were CommonJS.
Please don't use uppercase for emphasis, see http://ycombinator.com/newsguidelines.html
Explaining in further detail: a feature of some module systems is dependency injection (yes, dependency injection can also be performed outside a module system, but the slides discusses module systems so we will too).
DI gives module systems the ability to instantiate objects using different dependencies. This is handy for things like testing, where eg, a name that would normally resolve to a network API module would instead be resolved to a stub module with pre-canned responses, so any calls to that network API module return consistent responses.
Lack of dependency injection in existing JS module systems (you can do it in AMD, but using file paths so it's kind of hacky) is cited in the angular docs as the reason Angular includes its own unique module system.
Weather people still use AMD or CommonJS or Angular modules after ES6 modules really depends on the feature set of ES6 modules. Hence asking about the feature set of ES6 modules.