0

seems to me that ES2015 Modules compiled with babel are simply compiling down to node's require which passes objects by reference (as expected for that implementation)

the question is of the ES2015 spec and going forward in a native ES2015 modules implementation, would that still be the case?

Ahmad Nassri
  • 1,299
  • 1
  • 12
  • 18

1 Answers1

3

All objects are reference values in JavaScript, they are never cloned unless you explicitly tell them to. So yes, that will still be the case.

In fact, ES6 modules are worse than that - imported bindings are not ordinary variables, they are real references to the exported variables (see here for an example), behaving more like properties of a "module object" than like constants (and that's what babel does compile them to).

Community
  • 1
  • 1
Bergi
  • 630,263
  • 148
  • 957
  • 1,375
  • I can tell that's the behavior here so I wasn't sure if its a limitation of transpilers (e.g. babel `const` assignment doesn't throw exception per spec) or in the Spec itself. btw I'm still trying to find the reference to this behavior described in the ES2015 spec? – Ahmad Nassri Mar 23 '16 at 06:02
  • @AhmadNassri: It's [all there](http://www.ecma-international.org/ecma-262/6.0/#sec-modules)? – Bergi Mar 23 '16 at 13:49