Skip to main content

Bug Tracker

Side navigation

#6808 closed bug (fixed)

Opened July 20, 2010 09:52PM UTC

Closed July 22, 2010 07:52PM UTC

Last modified March 09, 2012 01:31AM UTC

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:
Description

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.

Attachments (0)
Change History (3)

Changed July 20, 2010 09:54PM UTC by dareed comment:1

Changed July 21, 2010 08:22PM UTC by john comment:2

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

Changed July 22, 2010 07:52PM UTC by john comment:3

resolution: → fixed
status: newclosed