Skip to main content

Bug Tracker

Side navigation

#12566 closed bug (wontfix)

Opened September 19, 2012 11:26AM UTC

Closed September 19, 2012 11:52AM UTC

Last modified October 30, 2013 04:50PM UTC

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

Reported by: fvanderwielen@gmail.com 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) )

Attachments (0)
Change History (5)

Changed September 19, 2012 11:31AM UTC by fvanderwielen@gmail.com comment:1

properly aligned for easy observarion


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

Changed September 19, 2012 11:52AM UTC by dmethvin comment:2

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.

Changed December 20, 2012 03:27PM UTC by andrew@floatleft.com comment:3

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.

Changed December 20, 2012 03:33PM UTC by dmethvin comment:4

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.

Changed October 30, 2013 04:50PM UTC by gibson042 comment:5

#14497 is a duplicate of this ticket.