#9917 closed bug (duplicate)
$.data returns undefined for any stored false value
Reported by: | anonymous | Owned by: | anonymous |
---|---|---|---|
Priority: | blocker | Milestone: | None |
Component: | data | Version: | 1.6.2 |
Keywords: | Cc: | ||
Blocked by: | Blocking: |
Description
If you store 0, false or null as a value for the data, it will always return undefined. Reason being, if it is stored as a camelized key, the below condition will always fail, and then $.data will always return the nonexisting non-camelized data, which is undefined.
The offending code is this, at the end of the $.data function:
thisCache[ jQuery.camelCase( name ) ] || thisCache[ name ]
This problem is especially bad, if 0 is stored as the data, and during retrieval, it is expected to be of a numeric type. With undefined, any numerical expression will result in NaN.
The above code should be changed to :
var camelName = jQuery.camelCase(name); camelName in thisCache ? thisCache[camelName] : thisCache[name]
Change History (6)
comment:1 Changed 12 years ago by
Component: | unfiled → data |
---|---|
Owner: | set to anonymous |
Priority: | undecided → low |
Status: | new → pending |
comment:3 Changed 12 years ago by
Resolution: | → duplicate |
---|---|
Status: | pending → closed |
comment:5 Changed 12 years ago by
Priority: | low → blocker |
---|
Note: See
TracTickets for help on using
tickets.
Thanks for taking the time to contribute to the jQuery project! Please provide a complete reduced test case on jsFiddle to help us assess your ticket!
Additionally, be sure to test against the jQuery Edge version to ensure the issue still exists. To get you started, use this boilerplate: http://jsfiddle.net/FrKyN/
Open the link and click to "Fork" (in the top menu) to get started.