在函数定义中,星号意味着什么,如“function *()”? [英] What does the star mean in function definition like "function* ()"?
本文介绍了在函数定义中,星号意味着什么,如“function *()”?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
function*() { .... }
我刚刚发现这种形式的定义在其他一些js代码中,星星是什么意思呢?谢谢
I just found that form of definition in some other js code, what does the star mean indeed? Thanks
推荐答案
从这里
具有*令牌的函数被称为生成函数。两个一元运算符之后的
只允许在生成函数的直接体
中(即在体内但不嵌套在
另一个函数中):
A function with a * token is known as a generator function. The following two unary operators are only allowed in the immediate body of a generator function (i.e., in the body but not nested inside another function):
AssignmentExpression:
...
YieldExpression
YieldExpression:
"yield" ("*"? AssignmentExpression)?
如果产生yield或yield *一个
非生成函数。
An early error is raised if a yield or yield* expression occurs in a non-generator function.
同时查看 MDN 和 这是什么东西叫做发电机?
Also check the MDN and What Is This Thing Called Generators?
这篇关于在函数定义中,星号意味着什么,如“function *()”?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文