我已经阅读了 MDN 的文档,好吧,主要是关于新模块功能的好处,让我感到困惑的是关于 的小事情export,现在,让我们看看:
当我
export function foo(x) {
return x * x;
}
Run Code Online (Sandbox Code Playgroud)
或者
export const foo = (x) => {
return x * x
}
Run Code Online (Sandbox Code Playgroud)
两者都有效;
但如果
const foo = (x) => {
return x * x
}
export foo // failed
Run Code Online (Sandbox Code Playgroud)
我知道这里应该是export {foo},但是,为什么呢?有什么区别,那应该是工作。很高兴听到一些精灵的想法。