简体   繁体   English

Javascript ES6 +命名为默认导出语法

[英]Javascript ES6+ named default export syntax

Is this valid export syntax? 这是有效的导出语法吗?

export default debug = {
    myfunction: myFunction
};

Default export syntax is correct. 默认导出语法正确。

But one catch here the variable 'debug' needs to be decalred. 但是这里需要注意的是,变量“ debug”需要进行标定。

You do something like below: 您可以执行以下操作:

export default {
    myfunction: myFunction
}

or 要么

const deb = {
    myfunction: myFunction
}
export default deb;

As debug is not defined when you assign your export object to it, and modules are run in strict mode , no. 由于在将导出对象分配给它时未定义调试,并且模块在严格模式下运行 ,否。 This is not valid. 这是无效的。 If you feel you must export a named object, you must declare it first. 如果您觉得必须导出命名对象,则必须先声明它。

let debug;
export default debug = {};

Note that you cannot declare the variable and export it in the same line. 请注意,您不能声明变量并将其导出到同一行。

export default const debug = {}; // invalid

From MDN : MDN

Note that it is not possible to use var, let or const with export default. 请注意,无法将var,let或const与export default一起使用。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM