Bug Tracker


Ticket #11962 (closed bug: fixed)

Opened 22 months ago

Last modified 22 months ago

Standardize getter return values for empty sets.

Reported by: cowboy Owned by:
Priority: low Milestone: 1.8
Component: attributes Version: 1.7.2
Keywords: Cc:
Blocking: Blocked by:

Description (last modified by cowboy) (diff)

Just like getter-setter detection logic has been standardized on arguments, it might be a good idea for empty-set getters to always return a consistent value. I vote for null.

I also understand if .text() must continue to behave differently, because it's already a special case in other ways, and we need something to laugh at ironically.

$.fn.jquery   // "1.7.2"
$().attr("x") // undefined
$().prop("x") // undefined
$().css("x")  // undefined
$().val()     // undefined
$().text()    // ""
$().html()    // null
$().offset()  // null

Please don't do this in a patch release, though! <3 (zing)

Change History

comment:1 Changed 22 months ago by cowboy

  • Description modified (diff)
  • Summary changed from Standardize getter return values on empty set. to Standardize getter return values for empty sets.

comment:2 Changed 22 months ago by dmethvin

  • Priority changed from undecided to low
  • Status changed from new to open
  • Component changed from unfiled to attributes
  • Milestone changed from None to 1.8

I'd prefer undefined since that changes fewer cases and avoids the Object-ness of null. Neither .html nor .offset have documented returns for empty sets so it should be safe to change. No way we're messing with .text buddy. :)

comment:3 Changed 22 months ago by Uri Gilad

  • Status changed from open to closed
  • Resolution set to fixed

Fix #11962. Standardize getter return values for empty sets.

Changeset: 21b0db7993315f0a5390798fefe63eb21891493e

Please follow the  bug reporting guidlines and use  jsFiddle when providing test cases and demonstrations instead of pasting the code in the ticket.


Add a comment

Modify Ticket

as closed

E-mail address and user name can be saved in the Preferences.

Note: See TracTickets for help on using tickets.