遗留的生成器函数

非标准
该特性是非标准的,请尽量不要在生产环境中使用它!

已废弃 Gecko 58 (Firefox 58 / Thunderbird 58 / SeaMonkey 2.55)
This feature is obsolete. Although it may still work in some browsers, its use is discouraged since it could be removed at any time. Try to avoid using it.

遗留的生成器函数是 SpiderMonkey 专有特性,已在 Firefox 58+ 中被移除。请考虑使用 function*

遗留的生成器函数声明使用特殊的参数声明遗留的生成器函数。

也可以使用带有 functionBody、至少一个 yield 表达式,和遗留的生成器函数表达式,配合 Function 构造器,来定义遗留的生成器函数。

语法

function name([param,[, param,[..., param]]]) {
   [statements]
}
name
函数名。
param
传入函数的参数名,一个函数最多有 255 个参数。
statements
构成函数体的语句。应至少含有一个 yield 表达式。

描述

用法概述可在迭代器和生成器页面上查看。

浏览器兼容性

Update compatibility data on GitHub
DesktopMobileServer
ChromeEdgeFirefoxInternet ExplorerOperaSafariAndroid webviewChrome for AndroidFirefox for AndroidOpera for AndroidSafari on iOSSamsung InternetNode.js
Legacy generator function
DeprecatedNon-standard
Chrome No support NoEdge No support NoFirefox No support 2 — 58IE No support NoOpera No support NoSafari No support NoWebView Android No support NoChrome Android No support NoFirefox Android No support 4 — 58Opera Android No support NoSafari iOS No support NoSamsung Internet Android No support Nonodejs No support No

Legend

No support  
No support
Non-standard. Expect poor cross-browser support.
Non-standard. Expect poor cross-browser support.
Deprecated. Not for use in new websites.
Deprecated. Not for use in new websites.

参考