export default 导出箭头函数

从小程序开放社区的一个问题,想到这么多

https://developers.weixin.qq....

https://developers.weixin.qq.com/community/develop/doc/000e62dcda4b087b142974a1056400

下面的export语句给出了语法错误

export default const hello = () => console.log("say hello")

为什么?

我只能导出命名函数

export function hello() {
  console.log("hello")
}

是什么原因?

最佳答案

Is it possible to export Arrow functions in ES6/7?

是. export不关心您要导出的值.

The export statement below gives a syntax error … why?

您不能使用默认导出并为其命名(“默认”已经是导出的名称).

要么这样做

export default () => console.log("say hello");

要么

const hello = () => console.log("say hello");
export default hello;

评论

暂无评论