Ticket #6992 (closed enhancement: wontfix)
data() can be used as data
|Reported by:||marian||Owned by:|
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.jq-enhanced] >>> $('body').data('foo') "bar" >>> $('body > div').data('foo') null
– 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' "bar" >>> $('body').data['foo'] "bar"
… until here:
>>> $('body > div').data['foo'] "bar"
As I said, I know this is not a bug, and I understand where the behavior comes from – all datas 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 :-) )