是否可以导出ES6 / 7中的箭头功能? [英] Is it possible to export Arrow functions in ES6/7?

查看:106
本文介绍了是否可以导出ES6 / 7中的箭头功能?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

下面的导出语句提供语法错误

The export statement below gives a syntax error

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

为什么?

我只能导出命名函数

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

原因是什么?

推荐答案


是否可以导出ES6 / 7中的箭头功能?

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

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

Yes. export doesn't care about the value you want to export.


导出下面的语句给出了一个语法错误...为什么?

The export statement below gives a syntax error ... why?

你不能有默认导出给它一个名称(默认已经是导出的名称)。

You cannot have a default export and give it a name ("default" is already the name of the export).



Either do

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

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

这篇关于是否可以导出ES6 / 7中的箭头功能?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆