__proto__ and JSON

Felix Böhm esdiscuss at feedic.com
Wed May 30 05:07:34 PDT 2012


After reading that __proto__ is becoming standardized, I was wondering what
the impacts on JSON would be. JSON is a subset of ECMAScript, so __proto__
would break current semantics. Even worse, try to run JSON.parse('{"__proto__":
1}'). The result in Chrome is an empty object. It doesn't inherit from
Number.prototype, the __proto__ property simply gets ignored. In terms of
portability, that's really bad.

The only solution I can think of would be the {prop = value} syntax, so
that __proto__ can only be set via {__proto__ = obj}. Considering that this
syntax is intended to trigger setters, it would make a lot of sense.

I know that existing code will break, even some of my own scripts use
__proto__ with the old syntax. But I knew that __proto__ is proprietary,
and I didn't expect it to work forever.

Otherwise, the JSON spec needs to be changed. I doubt that Doug Crockford
would support that.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.mozilla.org/pipermail/es-discuss/attachments/20120530/62b5fb0c/attachment.html>


More information about the es-discuss mailing list