FW: JSON.stringify replacer array semantics
douglas at crockford.com
Mon Jun 8 18:06:02 PDT 2009
Allen Wirfs-Brock wrote:
> Doug and Rob,
> Did you have any opinion on these two item (see below):
> 1) should the content of an replacer array be copied at the start of stringify such that it can't be side-effected during stringify processing? Oliver claims that FF 3.5 does such an internal copy and that json2.js also does so. IE8 does not make a copy and my reading of json2.js (pulled today from json.org) disagrees with Oliver's (I think it doesn't copy).
> However, making a copy does seem like a reasonable thing to specify.
If I could have written json2.js using the ES5 language, I would have used
Object.keys, not for..in, to obtain the keys. I think it would be good to avoid
the side effect hazard that for..in is subject to, particularly in the presence
of mutating getters.
> 2) should ToString be applied to the elements of an replacer array?
> Currently this is not done in the ES5 spec. Oliver reports that FF 3.5 does
> IE8 does not. json2.js does not. Is this a reasonable departure from the
It seems like an unnecessary step to me. Perhaps it would be better to throw?
More information about the es5-discuss