Skip to content

Instantly share code, notes, and snippets.

@john012343210
Last active November 11, 2018 04:28
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save john012343210/681d0eeeb927e7d1ff23f8881f747eba to your computer and use it in GitHub Desktop.
Save john012343210/681d0eeeb927e7d1ff23f8881f747eba to your computer and use it in GitHub Desktop.

the problem is that the variable i, within each of the inside anonymous functions, is bound to the same variable outside of the function.

we could just do this

function createfunc(k) { return function(i) { return i+k; }; }

function createArrayOfFunctions(y){ for (var i = 0; i < j; i++) { var arr = []; arr[i] = createfunc(i); } }

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment