Consider extending JSON grammar to support objects with circular reference
russell.leggett at gmail.com
Tue Mar 6 11:14:12 PST 2012
2012/3/6 Brendan Eich <brendan at mozilla.org>
> 程劭非 wrote:
> > I am just thinking we need a way to serialize/unserialize a js object
> > with circular reference to itself.
> Not just circular references, join points as well (anything making the
> object graph not a tree).
> As Allen suggested, with ES6 facilities including WeakMaps, this is best
> solved via library development and competition. You want github, not
> Ecma TC39, sorting it out.
This isn't too difficult to do in a library. I've done it, I think Ember.js
does it, and I think there's some other more generic library that does it,
but I couldn't find it. The way I do it is by a convention where objects
have ids and there can be references to those ids. Then I do a JSON.parse
and walk the object graph after to do the rest of the magic. Performance
hasn't been an issue (at least for me). Its really not that hard to do, and
until it gets more widely used, I agree that it doesn't make sense to
consider adding to the language.
> es-discuss mailing list
> es-discuss at mozilla.org
-------------- next part --------------
An HTML attachment was scrubbed...
More information about the es-discuss