Syntax question
Syntax question
I believe that generally this:
var divs = document.getElementsByTagName('div');
for(var i=0, k=divs.length; i<k; i++){
divs [i].onclick = doThis;
}
function doThis(e){ ... }
is better than:
var divs = document.getElementsByTagName('div');
for(var i=0, k=divs.length; i<k; i++){
divs[i].onclick = function(){ ... }
}
... because you're not creating an anonymous function for each div
event, just a pointer to the function.
Does it therefore follow that this:
$('DIV').click(doThis);
function doThis(){ ... }
is smarter than
$('DIV').click(function(){ ... })
... or does jquery do something clever with the function to make sure
there's just lots of references to it anyway?
A