The legacy generator function is a SpiderMonkey-specific feature, and will be removed at some point. For future-facing usages, consider using {{jsxref("Statements/function*", "function*")}}.
{{jsSidebar("Statements")}}
Summary
The legacy generator function statement declares legacy generator functions with the specified parameters.
You can also define functions using the {{jsxref("Function")}} constructor with functionBody
and at least one {{jsxref("Operators/yield", "yield")}} expression, and a {{jsxref("Operators/Legacy_generator_function", "legacy generator function expression", "", 1)}}.
Syntax
function name([param,[, param,[..., param]]]) { [statements] }
-
name
- The function name.
-
param
- The name of an argument to be passed to the function. A function can have up to 255 arguments.
-
statements
- The statements which comprise the body of the function. This should contain at least one {{jsxref("Operators/yield", "yield")}} expression.
Description
An overview of the usage is available on the Iterators and Generators page.
Browser compatibility
{{CompatibilityTable}}
Feature | Chrome | Firefox (Gecko) | Internet Explorer | Opera | Safari |
---|---|---|---|---|---|
Basic support | {{CompatNo}} | {{ CompatVersionUnknown}} | {{ CompatNo}} | {{ CompatNo}} | {{CompatNo}} |
Feature | Android | Chrome for Android | Firefox Mobile (Gecko) | IE Mobile | Opera Mobile | Safari Mobile |
---|---|---|---|---|---|---|
Basic support | {{CompatNo}} | {{CompatNo}} | {{CompatVersionUnknown}} | {{CompatNo}} | {{CompatNo}} | {{CompatNo}} |
See also
- {{jsxref("Generator")}}
- The legacy generator function expression
- The legacy Iterator protocol
- {{jsxref("Operators/yield", "yield")}}
- Functions and function scope
- {{jsxref("Statements/function", "function")}}
- {{jsxref("Operators/function", "function expression")}}
- {{jsxref("Function")}}
- {{jsxref("Statements/function*", "function*")}}
- {{jsxref("Operators/function*", "function* expression")}}
- {{jsxref("GeneratorFunction")}}
- The Iterator protocol