简体   繁体   中英

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.

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 :

Note that it is not possible to use var, let or const with export default.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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