People say: “Declaring a function in a loop is dirty and potentially error-prone,” but functions inside loops are what are explicitly specified, for example, in the Array.prototype.forEach method. Just because the word “function” should theoretically mean its new definition in every forEach call does not mean that it is actually defined every time by the Javascript engine .
The same applies to external loops, since the engines are "lazy" processing instructions. They are not going to redefine the entire forEach / Map / etc construction statement again, if nothing really has changed, they will simply pass new arguments to it.
The days of the ancient JS engines that did not know anything about such simple things, as well as about the context of the code, are long gone. And yet we get this ancient warning, which was conceived when functions could not yet be passed as arguments, as in the cases forEach or Map.
DDRRSS Feb 03 '19 at 11:10 2019-02-03 11:10
source share