Bug Tracker

Opened 7 years ago

Closed 7 years ago

Last modified 6 years ago

#12566 closed bug (wontfix)

$.each and ($.map or $.grep) callbacks - different function profiles but very similar

Reported by: fvanderwielen@… Owned by:
Priority: undecided Milestone: None
Component: unfiled Version: 1.7.1
Keywords: Cc:
Blocked by: Blocking:

Description

the function profile of the callback of $.each is different from $.map or $.grep, even though they are very similar. They all serve a very simmilar purpose and look very alike on other aspects as well, so it would make development easier if their function profiles would be the same, instead of interchanged:

jQuery.grep( array, function(elementOfArray, indexInArray) [, invert] ) jQuery.map( array, callback(elementOfArray, indexInArray) ) jQuery.each( collection, callback(indexInArray, valueOfElement) )

Change History (5)

comment:1 Changed 7 years ago by fvanderwielen@…

properly aligned for easy observarion

jQuery.grep( array,      function(elementOfArray, indexInArray) [, invert] ) 
jQuery.map( array,       callback(elementOfArray, indexInArray) ) 
jQuery.each( collection, callback(indexInArray, valueOfElement) )

comment:2 Changed 7 years ago by dmethvin

Resolution: wontfix
Status: newclosed

Agreed, but they were defined years ago so there is no way to "fix" it without breaking a lot of code. So we will need to expect people to read the documentation.

comment:3 Changed 7 years ago by andrew@…

Is there any chance that this could be a 2.0 feature? I understand that will contain many breaking changes anyway, why not change $(el).map, $.map, $.each and any other iteration methods to follow the ECMAScript standard of (index, element)?

This has always bugged me and 2.0 could be a great opportunity to get it fixed.

comment:4 Changed 7 years ago by dmethvin

Nope, because that would make the 1.9 and 2.0 APIs incompatible. If you are using 2.0 you can just use the native EcmaScript methods anyway since the browsers it supports all have them.

comment:5 Changed 6 years ago by gibson042

#14497 is a duplicate of this ticket.

Note: See TracTickets for help on using tickets.