String.prototype.toString = function() { return "custom"; }; JSON.stringify(new String("original"))

Jeff Walden jwalden+es at MIT.EDU
Thu Apr 8 16:36:10 PDT 2010


The spec currently says this code should evaluate to '"custom"'.  WebKit, Chrome, and IE8 do this (can't get IE9 preview to work testing this, assuming it hasn't changed).  Opera and Firefox don't.  json2.js doesn't special-case String or Number object handling (or Boolean for that matter, but while Number uses ToNumber and String uses ToString, Boolean uses [[PrimitiveValue]]), so compatibility with it is irrelevant.  Using [[PrimitiveValue]] is faster and more intuitive, I think, but it's not what the spec says, so if we liked [[PrimitiveValue]] more it would require an erratum.  What does anyone else think here?  Of course, it's not hard for Firefox to change, but it doesn't seem necessarily desirable to do so.

Jeff


More information about the es5-discuss mailing list