kriskowal/es5-shim — Issue #95: Correct bad Date.prototype.toJSON polyfills from elsewhere
Author: petermichaux
Created: 2012-01-29 17:54:06+00:00
State: open

Douglas Crockford's json2.js, for example, defines a Date.prototype.toJSON function that does not pad extended years with zeros as the es5-shim does in Date.prototype.toISOString does.

es5-shim can redefine a bad Date.prototype.toJSON by changing

if (!Date.prototype.toJSON) {

to

if (!Date.prototype.toJSON ||
(new Date(-62198755200000).toJSON().indexOf('-000001') === -1)) {

This also means people using json2.js need to include json2.js in their environment before including es5-shim as defining Date.prototype.toJSON means other things will not be defined in json2.js