KnowledgeHub
Questions
Tags
Users
Search
Alex Rivera
|
Logout
Edit Question
Title
Body
A common pattern within jQuery is a method that takes a callback which is passed an element of an array and its index within that array. However, it seems completely random which argument comes first. For example, from the jQuery docs at http://api.jquery.com : jQuery.each( collection, callback(indexInArray, valueOfElement) ) .each( function(index, Element) ) jQuery.map( array, callback(elementOfArray, indexInArray) ) .map( callback(index, domElement) ) jQuery.grep( array, function(elementOfArray, indexInArray), [ invert ] ) .filter( function(index) ) In three cases ( jQuery.each , .each , .map ) the index comes first. In the other two ( jQuery.grep , jQuery.map ) the element comes first. I know the api is now set, but it seems like a gross inconsistency to me. Is there a pattern I'm missing or is this just random? Should this be fixed or should I just shut up and memorize them?
Tags (comma-separated)
Save Edits
Cancel