title: Javascript yield from the function nested inside generator
body: <p>This code generates an error:</p>
  
  <pre><code>function *giveNumbers() {
      [1, 2, 3].forEach(function(item) {
          yield item;
      })
  }
  </code></pre>
  
  <p>This is probably because yield is inside a function that is not a generator. Is there an elegant way to overcome this? I mean other than:</p>
  
  <pre><code>function *giveNumbers() {
      let list = [1, 2, 3];
      for (let i = 0; i &lt; list.length; i++) {
          yield list[i];
      }
  }
  </code></pre>