Does defining functions inside a loop affect performance?
Like
var doSomething = function(element){
$(element).whatever();
};
return this.each(function(){
doSomething(this);
})
vs
return this.each(function(){
var element = this,
doSomething = function(){
element.whatever();
};
doSomething();
...
})
In 2nd version the function gets defined like 324532453245 times, depending on how many elements are being iterated, right?
Technically, you’re defining a defining the functions 80 bajillion times or so in both versions. For high volumes of iteration, you should get some performance benefit from defining it like this.