Skip to main content

Bug Tracker

Side navigation

#11962 closed bug (fixed)

Opened June 23, 2012 12:15PM UTC

Closed July 10, 2012 03:11AM UTC

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:
Blocked by: Blocking:
Description

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)

Attachments (0)
Change History (3)

Changed June 23, 2012 12:25PM UTC by cowboy comment:1

description: 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! <3Just 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)
summary: Standardize getter return values on empty set.Standardize getter return values for empty sets.

Changed July 03, 2012 05:28PM UTC by dmethvin comment:2

component: unfiledattributes
milestone: None1.8
priority: undecidedlow
status: newopen

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. :)

Changed July 10, 2012 03:11AM UTC by Uri Gilad comment:3

resolution: → fixed
status: openclosed

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

Changeset: 21b0db7993315f0a5390798fefe63eb21891493e