title: Can I use function generator as event handler?
body: <p>I have a list of HTMLCollection:</p>
  <pre><code>&lt;div class=&quot;demo&quot;&gt;Access me by class[1]&lt;/div&gt;
  &lt;div class=&quot;demo&quot;&gt;Access me by class[2]&lt;/div&gt;
  &lt;div class=&quot;demo&quot;&gt;Access me by class[3]&lt;/div&gt;
  &lt;div class=&quot;demo&quot;&gt;Access me by class[4]&lt;/div&gt;
  </code></pre>
  <p>And I have a script of JS:</p>
  <pre><code>var getElements = document.getElementsByClassName(&quot;demo&quot;);
  const generatorObject = generatorFunction();
  
  function* generatorFunction(e) { 
      for (i = 0; i &lt; getElements.length; i++) { 
          yield getElements[i];
      }
  }
  
  generatorObject.next(); // each time pressed a key down will invoke this line 
  // after invoking 6th time it will give {value: undefined, done: done}
  </code></pre>
  <p>My goal is to write a <code>keyboardEvent</code> based on <code>.addEventListener(&quot;keydown&quot;, generatorFunction)</code> method whereby event handler would be presented as function generator i.e. <code>generatorFunction</code> presented above. Is it good or bad practice?</p>