All:
I am pretty new to ES6, when I study ES6 module with this post:
http://www.2ality.com/2014/09/es6-modules-final.html
[1]
there is one line:
export { each as forEach };
I wonder if anyone could tell where can I find the usage intro to this specific syntax (especially the curly bracket and AS
)
[2]
Another confuse is about default export:
cmod.js
export default var Obj={};
Obj.hello = function(){
return "hello";
}
main.js
import hello from "./cmod"
console.log(hello.hello());
I wonder why I got error like: :
SyntaxError: cmod.js: Unexpected token (1:15)
> 1 | export default var Obj={};
| ^
But if I move the declaration to a separated line like:
var Obj = {}
export default Obj;
Obj.hello = function(){
return "hello";
}
Then everything works, why I can not declare a variable and export it?
Thanks
default
exports syntax simply doesn't allow this. Doexport default { hello: ... };
orvar Obj = { ... }; export default Obj
. – Felix Kling