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

polyfill VS native: possible enhancement #2

Closed WebReflection closed 8 years ago

WebReflection commented 8 years ago

I wonder if, in case System is missing, it wouldn't be better to reflect a native descriptor.

if (typeof System !== 'object') {
  Object.defineProperty(global, 'System', {
    configurable: true,
    writable:  true,
    value: {}
  });
}

Moreover, I believe the global property in the System should actually throw if reassigned or, at least, be a constant, like the PI in the Math object.

if (!System.global) {
  Object.defineProperty(Symbol, 'global', {value: global});
}

What do you think?

ljharb commented 8 years ago

The "polyfill" in the proposal repo is an example implementation and isn't meant to be consumed, simply a reference implementation.

Once the naming issue is resolved, I'll release a module on npm that uses define-properties to do exactly as you suggest.