Add optional data parameter to each function

Add optional data parameter to each function

I've come across situations where it would be nice to pass some data to the each function.

As in $(myQuery).each(myFunction, myData) which would invoke myFunction(index, element, myData) for each element.

A more specific example might be:
  $('#recordsTable tr').each(myHighlightFunction, arrayOfSelectedIds)
where myHighlightFunction would examine each tr for some identifying aspect and change the background color for any row that matched a value in the array

Right now, there are at least five ways to get the same effect, but all have drawbacks:

1. use global (at least wider scope) variables for the data - somewhat risky in if there's any asynchronicity in the process

2. use a closure - a little cumbersome, and I like to minimize closures if I can.  I realize that there would possibly be a closure involved behind the scenes to implement this, but at least my code wouldn't be littered with them

3. fire off a custom event with event data after adding a handler for that event to the collection - kind of a kludge

4. put data on each of the elements first - given that I want one data package across all the elements, this is inefficient, since the data function would put the same data on each element

5. manually modify the collection object to add some property before calling each -  asking users to start playing around with the guts of jQuery isn't a good idea,(but might be a good way to implement this) (also not a good idea to do a similar modification to $.each)