JSlint error 'Don't make functions within a loop.' leads to question about Javascript itself
- 阅读更多 关于 JSlint error 'Don't make functions within a loop.' leads to question about Javascript itself
I have some code that invokes anonymous functions within a loop, something like this pseudo example: for (i = 0; i < numCards; i = i + 1) { card = $('<div>').bind('isPopulated', function (ev) { var card = $(ev.currentTarget); .... JSLint reports the error 'Don't make functions within a loop.' I like to keep my code JSLint clean. I know I can move the anonymous function out of the loop and invoke it as a named function. That aside, here's my question: Would a Javascript interpreter really create an instance of the function per iteration? Or is there really only one function instance "compiled"