tc39 / proposal-global

ECMAScript Proposal, specs, and reference implementation for `global`
http://tc39.github.io/proposal-global/
MIT License
349 stars 18 forks source link

Is it problematic that System.global is a circular structure? #6

Closed joeldenning closed 8 years ago

joeldenning commented 8 years ago

If I understand the spec correctly, System.global === System.global.System.global === System.global.System.global.System.global. Are there any problems with this? Potentially that JSON.stringify(System) will throw errors since it now contains circular references.

ljharb commented 8 years ago

JSON.stringify(window) in browsers and JSON.stringify(global) in node already have this problem, since they already contain window.window and global.global respectively. Naively stringifying an object, especially a global one, just isn't something that anyone needs to be concerned about :-)

joeldenning commented 8 years ago

I totally agree that stringifying the window doesn't make sense. What I was thinking was that perhaps stringifying the System object might make a bit more sense, especially since there are many other proposals (both ecmascript specs and in userland) that plan on putting properties on the System object (i.e., whatwg/loader's System.loader spec, or SystemJS' configuration options that are put on the System object).

However, as I think about this more, I don't think that that is an especially strong use case either. And I can't think of any other reason why a circular structure would be undesirable. So I agree that this is not really a problem.

ljharb commented 8 years ago

Reflecting/introspecting on System, absolutely! Stringifying it en-masse, however - especially when JSON doesn't support functions and most of the useful things are functions - doesn't seem that likely.