Looking at the docs for the .each() function in jquery shows the following method signature:
.each( function(index, Element) )
http://api.jquery.com/each/
I can understand needing to pass in an index so that it is available for use within the callback but why would you explicitly include the Element parameter if you can just reference the current element by the this
keyword? Is it there just so that you can specify an instance name of your choice? I mean, if you still have to wrap a named instance in the jquery method $()
to get back a jquery object isn't that exactly the same as this
? The docs don't seem to mention why it is there.
Update:
I think this has something to do with closures but I'm not sure. It seems like what I'm referring to as a "named instance" is actually a local copy or clone of the element in the array stored in a variable within the scope of the callback. I suspect that by using this
it is referencing a variable as if it were some sort of closure. @thecodeparadox found something in a firebug console that got me thinking about this. Still not quite sure what the difference is though or why you would ever need to have a locally scoped value of the element in the array.