Hacker News new | ask | show | jobs
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.

1 comments

Please read posts before replying to them.

- 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.

>- Nowhere in my post did I say a module system was dependency injection

Let me remind you then:

"Do ES6 modules have all the dependency injection stuff the Angular developers wanted?"

>Explaining in further detail: a feature of some module systems is dependency injection

An orthogonal, non relevant feature, that has nothing to do with the core role of a module system.

That some module systems have this frankensteinian stuff included doesn't mean much.

The statement you are bizarrely quoting quite clearly does not equate dependency injection with module systems.

Again, read HN guidelines, your account is quite new and it's very obvious you haven't done so yet.