Bug Tracker

Changes between Version 2 and Version 3 of Ticket #11785, comment 2


Ignore:
Timestamp:
May 19, 2012, 7:56:15 PM (10 years ago)
Author:
Robert Katić
Comment:

Legend:

Unmodified
Added
Removed
Modified
  • Ticket #11785, comment 2

    v2 v3  
    11I think `findFirst()` is more appropriate then `findOne()` for several reasons: 1) It is more similar to the `.first()` method and the `:first` filter. 2) it removes any doubt in case of not simple selectors. Consider `".boo, .foo"`. We expect the `".foo"` element if it precedes the `".boo"` one, becouse it is how `querySelector()` works.
    22
    3 So, I suggest three additions:
    4   1. `jQuery.findFirst()`, that behaves like `jQuery.find("...")[0] || null`.
    5   2. `jQuery.first()`, that returns `jQuery( jQuery.findFirst("...") )`. **OPTIONAL**
    6   3. `jQuery.fn.findFirst()`...
     3So, I suggest ~~three~~ two additions:
     4  1. `jQuery.findFirst()`, that behaves like `jQuery.find("...")[0] || null`
     5  2. `jQuery.fn.findFirst()`...
     6  3. ~~`jQuery.first()`, that returns `jQuery( jQuery.findFirst("...") )`~~
    77
    88Note how those additions would play nicely with the existent API. For example:
    99
    10  * `$(".boo").first()` **or** `$.first(".boo")` **OPTIONAL**
    11  * `$(".foo").find(".boo:first")` **or** `$(".foo").findFirst(".boo")`
     10 * `$(".foo").find(".boo:first")` **or** `$(".foo").findFirst(".boo")`
     11 * ~~`$(".boo").first()` **or** `$.first(".boo")`~~
    1212
    13 **EDIT:** Rethinking, I come with the conclusion that `jQuery.first()` would introduce confusion to the API, since `.first()` is for "filtering" and not for "searching"... so I marked it as optional.
     13**EDIT:** Rethinking, I come with the conclusion that `jQuery.first()` would introduce confusion to the API, since `.first()` is for "filtering" and not for "searching"...