en.javascript.info icon indicating copy to clipboard operation
en.javascript.info copied to clipboard

Problem with sample program in Async Generators and Iterators article

Open paroche opened this issue 5 years ago • 3 comments
trafficstars

In Plunker, following Open in Sandbox link, code provided under "An example of use (shows commit authors in console):" doesn't work (because it doesn't include fetchCommits function).

Console shows error:

(index):9 Uncaught (in promise) ReferenceError: fetchCommits is not defined
(index):9 Uncaught (in promise) ReferenceError: fetchCommits is not defined
    at (index):9
    at (index):18

Running the code directly from the run link in article also doesn't work. Gives error:

holder-2.2.min.js:10 Uncaught TypeError: Cannot read property 'appendChild' of undefined
    at Object.e.run (holder-2.2.min.js:10)
    at holder-2.2.min.js:10
    at XMLDocument.h (holder-2.2.min.js:10)

Code in question:

(async () => {

  let count = 0;

  for await (const commit of fetchCommits('javascript-tutorial/en.javascript.info')) {

    console.log(commit.author.login);

    if (++count == 100) { // let's stop at 100 commits
      break;
    }
  }

})();

paroche avatar Feb 29 '20 04:02 paroche

Hi @paroche, the error is raised as fetchCommits() is a custom function (not part of the standard JavaScript language). This means this function needs to be defined before calling.

On javascript.info this is already included in the header which you can find here

Also the tutorial shows this function in the code snippet above the one you describe. So if you want to execute the code on plunker you need to copy/paste this dependent code as well.

joachimklug avatar Jun 21 '20 22:06 joachimklug

Maybe add a note about "where to find fetchCommit into the example, to avoid confusion?

iliakan avatar Jun 21 '20 23:06 iliakan

Hi @joachimklug

Yes, that's what I said in the first line of my post:

"In Plunker, following Open in Sandbox link, code provided under "An example of use (shows commit authors in console):" doesn't work (because it doesn't include fetchCommits function)."

@iliakan -- that would help, though I would think you would want the "Open in Sandbox" link to work.

paroche avatar Jun 22 '20 02:06 paroche