我可以在生成器中使用 ES6 的箭头函数语法吗?(箭头符号) [英] Can I use ES6's arrow function syntax with generators? (arrow notation)

查看:31
本文介绍了我可以在生成器中使用 ES6 的箭头函数语法吗?(箭头符号)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

也就是我怎么表达

function *(next) {}

使用箭头语法?我尝试了所有我能想到的组合,但找不到任何相关文档.

(我目前使用的是 Node.js v0.11.14.)

解决方案

我可以在生成器中使用 ES6 的箭头函数语法吗?

你不能.对不起.

根据 MDN<块引用>

function* 语句(function 关键字后跟一个星号)定义了一个生成器函数.

来自规范文档(我的重点):

<块引用>

function 语法被扩展为添加一个可选的 * 标记:

FunctionDeclaration:函数"*"?标识符 "(" FormalParameterList? ")""{" 函数体 "}"

That is, how do I express

function *(next) {}

with arrow syntax? I've tried all the combinations I could think of, and I can't find any documentation on it.

(I am currently using Node.js v0.11.14.)

解决方案

Can I use ES6's arrow function syntax with generators?

You can't. Sorry.

According to MDN

The function* statement (function keyword followed by an asterisk) defines a generator function.

From a spec document (my emphasis):

The function syntax is extended to add an optional * token:

FunctionDeclaration: "function" "*"? Identifier "(" FormalParameterList? ")" 
  "{" FunctionBody "}"

这篇关于我可以在生成器中使用 ES6 的箭头函数语法吗?(箭头符号)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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