function*
keyword can be used to define a generator function inside an expression.
function* [name]([param1[, param2[, ..., paramN]]]) {
statements
}
name
可选
paramN
可选
The name of an argument to be passed to the function. A function can have up to 255 arguments.
statements
包含函数本体的语句。
A
function*
expression is very similar to and has almost the same syntax as a
function* 语句
. The main difference between a
function*
expression and a
function*
statement is the
函数名称
, which can be omitted in
function*
expressions to create
anonymous
generator functions. See also the chapter about
函数
了解更多信息。
The following example defines an unnamed generator function and assigns it to
x
. The function yields the square of its argument:
let x = function*(y) {
yield y * y;
};
| 规范 |
|---|
|
ECMAScript (ECMA-262)
The definition of 'function*' in that specification. |
| Desktop | Mobile | Server | |||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
function*
|
Chrome 49 | Edge 12 | Firefox 26 | IE No | Opera 36 | Safari 10 | WebView Android 49 | Chrome Android 49 | Firefox Android 26 | Opera Android 36 | Safari iOS 10 | Samsung Internet Android 5.0 | nodejs 4.0.0 |
| Trailing comma in parameters | Chrome 58 | Edge 79 | Firefox 52 | IE No | Opera 45 | Safari 10 | WebView Android 58 | Chrome Android 58 | Firefox Android 52 | Opera Android 43 | Safari iOS 10 | Samsung Internet Android 7.0 | nodejs 8.0.0 |
完整支持
不支持
function*
statement
GeneratorFunction
object
yield
yield*
Function
object
function
statement
function
expression