Ticket #6968 (closed bug: fixed)
"handle" won't work as a key for .data() method
| Reported by: | itachi | Owned by: | snover |
|---|---|---|---|
| Priority: | blocker | Milestone: | 1.5 |
| Component: | data | Version: | 1.4.3 |
| Keywords: | needstest patch | Cc: | |
| Blocking: | #7840 | Blocked by: |
Description
--- to reproduce, evaluate:
/* any jQuery el */
var $el = $(document)
/* set "handle" to anything but a function */
$el.data("handle", {}))
/* this fails, see line 1850 where jQuery.trigger() function assumes that jQuery.data( elem, "handle" ) is a function */
$el.data("handle")
--- expected: "handle" keyword work or is marked invalid in docs
Change History
comment:2 Changed 3 years ago by dmethvin
- need changed from Review to Patch
Also used internally:
__className__ handle events _change_data lastToggle events olddisplay
comment:3 Changed 3 years ago by snover
- Priority set to blocker
- Status changed from new to open
- Version changed from 1.4.2 to 1.4.3
- Milestone changed from 1.4.3 to 1.next
We need to stop polluting the data objects with internal data. 1.4.3 also adds __events__ as a polluting key.
comment:7 Changed 3 years ago by cobexer
what about using jQuery.expando + "_events",...
this would remove all collision possibilities.
however it would also pollute the display in FireQuery (Firebug addon)
maybe reserve "jQuery." as prefix a user may not use
comment:8 follow-up: ↓ 12 Changed 3 years ago by iliakan
It seems sane to have $ as prefix for all jquery native stuff, or even $, like: "" as hidden library stuff and "$" pointing that it is jquery library stuff.
comment:12 in reply to: ↑ 8 Changed 2 years ago by gnarf
Replying to iliakan:
It seems sane to have $ as prefix for all jquery native stuff, or even $, like: "" as hidden library stuff and "$" pointing that it is jquery library stuff.
I kinda like that idea... .data('$')['events'] or .data('$events') either seems less polluting for the internals. I wonder how many people are using .data('events') or other internal keys for their own code/purposes though. Either suggestion would be easy enough to compat mode, making the .data strip the $ off the argument.
comment:13 Changed 2 years ago by snover
pull request i forgot to put this here.
comment:14 Changed 2 years ago by Colin Snover
- Status changed from assigned to closed
- Resolution set to fixed
Merge in data_nocollide branch. Fixes #6968, improves unit testing framework checks for leaky stuff.
Changeset: e78d3a7e2d47e9796f87c18b76f8178b0bee42c5
Please follow the bug reporting guidlines and use jsFiddle when providing test cases and demonstrations instead of pasting the code in the ticket.

Good point, perhaps it would be a good idea for jQuery to use a leading $ for its data names to avoid conflicts.