Previous versions of SpiderMonkey permitted the use of yield expressions in functions not marked as generators. This is no longer supported, and is not compliant with ECMAScript 2015.

Mark the enclosing function as a generator by replacing function with function*.

The following example uses yield to produce a sequence of indices, but the function idMaker is not marked as a generator:

This is easily fixed by adding an asterisk to the function keyword:

  • Mozilla Developer Network: function*.
  • Mozilla Developer Network: yield.