Freeman
Freeman

Reputation: 6216

.map() second argument of the callback function

What is the purpose of the second argument in the callback function .map()?

I think it is not necessary because you can use this instead:

> $('p').map(function (index, element) {
      return this===element;
});
[true, true, true, true]

Upvotes: 0

Views: 108

Answers (1)

Alnitak
Alnitak

Reputation: 339816

On useful feature is that if you call another closure inside the callback you've still got a "ready made" reference to the element, since this wouldn't be correct anymore.

Upvotes: 5

Related Questions