javascript - The output value of es6 module loading export is a bit unclear
淡淡烟草味
淡淡烟草味 2017-07-05 10:53:10
0
3
819


Why is this error reported?


Why is this okay? What is the function of the braces? Is this the syntax?

淡淡烟草味
淡淡烟草味

reply all (3)
刘奇

Before the es6 standard came out, whatever was exported was what was required.

Take nodejs as an example

// ./fk.js export 'fk'; // ./main.js var fk = require('./fk'); console.log(fk); // output "fk"

Look, this is not "modular" at all. Since the module is imported, it should have values, functions, cars, donkeys, and hot pots.

What to do?
The label stipulates that all exported content must have a "name". You can also give it an alias, but it must have a name anyway!

The first way to choose a name

export var/let/const 名字=值

Second method of naming

var/let/const 变量=值 export {变量} 或 export {变量 as 别名}

The third way to choose a name

export default 值

The second method in the first picture reports an error because you don’t use curly brackets. When compiling,mI don’t know what it’s called. If I don’t know what it’s called, I don’t have a name. I can’t come up with a name. It cannot be exported.

End.

    typecho

    See the documentation export on MDN

    There are only a few forms in total

    export { name1, name2, …, nameN }; export { variable1 as name1, variable2 as name2, …, nameN }; export let name1, name2, …, nameN; // also var export let name1 = …, name2 = …, …, nameN; // also var, const export default expression; export default function (…) { … } // also class, function* export default function name1(…) { … } // also class, function* export { name1 as default, … }; export * from …; export { name1, name2, …, nameN } from …; export { import1 as name1, import2 as name2, …, nameN } from …;

    The two forms you wrote are not included...For the specific meaning of each form, please read the document!

      给我你的怀抱

      https://developer.mozilla.org...

      For this kind of problem, just read the document directly. And didn’t you take this picture from Ruan Yifeng’s article? The original text has clear instructions

      It is important to note that the export command specifies the external interface and must establish a one-to-one correspondence with the variables inside the module.

      The above two writing methods will report errors because no external interface is provided. The first way of writing directly outputs 1, and the second way of writing directly outputs 1 through variable m. 1 is just a value, not an interface.

        Latest Downloads
        More>
        Web Effects
        Website Source Code
        Website Materials
        Front End Template
        About us Disclaimer Sitemap
        php.cn:Public welfare online PHP training,Help PHP learners grow quickly!