jQuery $.each(arr, foo) versus $(arr).each(foo)
Posted
by Brian M. Hunt
on Stack Overflow
See other posts from Stack Overflow
or by Brian M. Hunt
Published on 2010-06-08T12:41:05Z
Indexed on
2010/06/08
12:42 UTC
Read the original article
Hit count: 337
In jQuery, what's the difference between the following two constructions of jQuery.each
:
// Given
var arr = [1,2,3,4],
results = [],
foo = function (index, element) {
/* something done to/with each element */
results.push(element * element); // arbitrary thing.
}
// construction #1
$.each(arr, foo); // results = [1,4,9,16]
// construction #2
$(arr).each(foo); // results = [1,4,9,16]
Is there any difference, or is it purely syntax?
© Stack Overflow or respective owner