While the interface of .map() method is .map( callback(index, domElement) ), it’s $.map( array, callback(elementOfArray, indexInArray) ) for $.map()… Any idea over the reason why $.map() choose to place the returned arguments in an order such as value-index?
While the interface of .map() method is .map( callback(index, domElement) ) , it’s $.map(
Share
If you study the jQuery API you will notice that all methods that work on a set of selected elements and accept callbacks, such as
.each,.html,.text, etc., all pass the index of the element as first argument, i.e..mapis in line here. Usually you access the current element withthisinside the callback, this is just a common pattern in jQuery and so the developers might have decided that it is more important to have the index as first argument.On the other hand, the native
Array.prototype.mapmethod passes the value of element as first argument to the callback, so it seems to make sense that$.mapworks the same way, since it is supposed process a generic set of items.