4 ms·
Consistency has nothing to do with it. In jQuery you could just as well do: $.find('.foo').find('.bar') It's just a different way of invoking it. The shor
by aleem 11y ago
Consistency has nothing to do with it. In jQuery you could just as well do:
$.find('.foo').find('.bar')
It's just a different way of invoking it. The short-hand is more convenient since it accepts a selector as well as a plain DOM node and converts that to a jQuery elements. This makes things very easy and idiomatic.
- rubiquity 11y agoYeah but jQuery's find (and a ton of its other APIs) are so drastically different than any other programming language/library. `find` in just about any other language returns the first encounter of an item in a set, as opposed to jQuery's `find` which returns all matches in a set. And don't even get me started on how jQuery hijacks `this` in callbacks...
- juliangregorian 11y agojQuery's find is almost certainly more useful that way though, if not optimally named. I can't understand though why you would claim to dislike jQuery providing you a useful 'this'. You prefer to receive the window object?
- rubiquity 11y ago> jQuery's find is almost certainly more useful that way though, if not optimally named. Useful but poorly named isn't useful. > I can't understand though why you would claim to dislike jQuery providing you a useful 'this'. I prefer programming language libraries to work according to the semantics of the underlying programming language. Is that so wrong?
- juliangregorian 11y agoCome off it. JavaScript's 'this' is meant to be usable in such a manner. http://es5.github.io/#x15.3.4.3 http://es5.github.io/#x15.3.4.3
- rubiquity 11y agoUsing bind like that is perfectly fine in application code but I consider that a big violation of Principle of Least Surprise in library code. Nearly every programming language in existence has some feature(s) that you can shoot yourself in the foot with. Does that mean you should do it?
- juliangregorian 11y agoIt's pretty standard practice for JavaScript libs. How much do you actually use JavaScript?