I agree. As said, it was an unfortunate blunder that will probably remain for the forseeable future.
On the plus side, it's not terribly hard to work around, and if it's a major problem you can overwrite the jQuery.fn.each function, or even jQuery.each (it shouldn't be that big of a deal, though). On Aug 11, 9:31 am, Daniel Friesen <nadir.seen.f...@gmail.com> wrote: > Event callback: function(eventObject) { this = domnode }// Because > that's the way events have always worked > each() callback: function(index, sameAsThis) { this = item/domnode } // > Keeping the pattern > map() callback: function(index, sameAsThis) { this = item/domnode } // > Keeping the pattern > filter() callback: function(index) { this = item/domnode } // sorta > keeping the pattern > vs. > Event callback: function(eventObject) { this = domnode } // event > callbacks MUST use this as domnode, otherwise you destroy the api it was > based on > each() callback: function(item, index?) { ... } > map() callback: function(item, index?) { ... } > filter() callback: function(item, index?) { ... } > > Whether you like it or not, jQuery is a library for working with the > dom. Thus when created each/map/filter had nothing to do with the array > methods that have only been put into browsers recently (yes, recently... > you are comparing standards set by new features, with decisions that > were made years ago; not the best comparison), they were created to give > control over the jQuery object's list of dom nodes. Thus, since all the > other apis which worked with dom nodes used `this` to refer to the dom > node that same api was used when writing those methods. > It's only a side effect that these methods happen to be usable on > non-domlist arrays. Though frankly, imho that is abuse, these methods > are not meant for that purpose, you can plainly see that in how $.fn.map > differs from Array.prototype.map in how it folds arrays into the list > rather than adding them as items. > > ~Daniel Friesen (Dantman, Nadir-Seen-Fire) [http://daniel.friesen.name] > --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "jQuery Development" group. To post to this group, send email to jquery-dev@googlegroups.com To unsubscribe from this group, send email to jquery-dev+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/jquery-dev?hl=en -~----------~----~----~----~------~----~------~--~---