Bug Tracker

Opened 13 years ago

Closed 13 years ago

Last modified 11 years ago

#6808 closed bug (fixed)

jQuery.fn.data on JavaScript objects adds the jQuery Expando, which survives JSON serialization

Reported by: dareed Owned by:
Priority: Milestone: 1.4.3
Component: data Version: 1.4.2
Keywords: data plainobject Cc:
Blocked by: Blocking:


Currently doing this:

$(obj).data("foo", "bar");

Or anything that uses data() (such as bind()), causes the expando to be added:

alert(obj[jQuery.expando]); <somevalue>

This value is serialized with the object if it is JSON serialized, which can be a problem for the other end of an AJAX call that expects the JSON to be of a specific format.

jQuery.fn.data should use a function added to the object to contain the expando value rather than a direct field. No JSON serializer will serialize a function. There is only a bit more indirection in getting the value, which should be minimal.

Note that this change is in conflict with ticket 6807, which changes data() to set fields directly on regular objects. If that ticket is resolved, this one is not necessary. If that one is not resolved, this is a much smaller and simpler change that can be taken separately.

Change History (3)

comment:2 Changed 13 years ago by john

I've left feedback on the fork - please drop me an email when you reply (trac email notifications are weird).

comment:3 Changed 13 years ago by john

Resolution: fixed
Status: newclosed
Note: See TracTickets for help on using tickets.