Skip to main content

Bug Tracker

Side navigation

#6992 closed enhancement (wontfix)

Opened September 02, 2010 08:46PM UTC

Closed October 03, 2010 02:57AM UTC

data() can be used as data[]

Reported by: marian Owned by:
Priority: undecided Milestone: 1.4.3
Component: data Version: 1.4.2
Keywords: Cc:
Blocked by: Blocking:

I've noticed a strange behavior (I don't want to say it's a bug):

Normally, you use data this way:

>>> $('body').data('foo', 'bar')
>>> $('body').data('foo')
>>> $('body > div').data('foo')

– everything's fine, other elements are not affected.

However if one uses it as follows, which is not that digressive IMHO (at least it was how I used it without thinking about it), everything seems also fine: …

>>> $('body').data['foo'] = 'bar'
>>> $('body').data['foo']

… until here:

>>> $('body > div').data['foo']

As I said, I know this is not a bug, and I understand where the behavior comes from – all

s of all elements are the same object, and, well,
does write on the object directly.

But nonetheless, I want to ask whether something can be done here to avoid this mistake, which is somehow self-evident and, I assume, made often. (It took me a looong time to find out that this was the reason :-) )

Attachments (0)
Change History (3)

Changed September 03, 2010 12:30AM UTC by dmethvin comment:1

I'm not sure how we could prevent this. You're assigning values to properties of the

method. People have made similar mistakes like
 $("body").innerHTML = "hello""  
that are also pretty difficult to detect. Ecmascript 5 will have the ability to seal objects to prevent new properties/methods from being assigned, but for now with existing browsers I don't see a solution.

Changed September 03, 2010 12:31AM UTC by dmethvin comment:2

component: unfileddata
type: bugenhancement

Changed October 03, 2010 02:57AM UTC by dmethvin comment:3

priority: → undecided
resolution: → wontfix
status: newclosed

No way we can fix this, unfortunately.