There were no test cases that applied in 1.4.4. JSON serialization was never tested explicitly. The only internal property that was hidden in this way was the internal
events property, which was far from the only property that was potentially added to objects. The only test that existed in the 1.4.4 suite was “is
events a function when added to a plain JS object?”. There was never an explicit test to see what a serialized object actually looked like until I added it along with this patch, and then it turned out that it only passed in IE and browsers that had started implementing ES5 (which changed the property to
It’s a problem for three reasons.
1. ES3 exposes a
prototype property by default as a non-deletable, enumerable value of the function instance. This means that it’s impossible to have a truly empty function instance in an ES3 environment: iterating through the instance always shows it as having a
prototype property that cannot be deleted. This means that an “empty” data structure actually has properties, which means that a bunch of other tests start to fail, and the only way to work around those is to add more hacks in jQuery to deal with and ignore the potential existence of a
2. Using a function instance ignores the very real possibility of people extending Function.prototype with their own shit which ends up being enumerable on function instances, further breaking the ability to determine whether or not the data structure is empty. Unlike Object.prototype, modifying Function.prototype is not verboten, and occurs with relatively high frequency, especially with polyfills for ES5.
3. Safari 4’s native JSON.stringify treats a Function like an Object and serializes it anyway.
There is a simple and much more viable alternative for people that want to serialize objects with attached metadata (replacer function). Please use it.