Skip to content

Instantly share code, notes, and snippets.

@WebReflection
Last active July 11, 2018 10:31
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save WebReflection/56d04ccb1e5b0e50c121 to your computer and use it in GitHub Desktop.
Save WebReflection/56d04ccb1e5b0e50c121 to your computer and use it in GitHub Desktop.
An attempt to polyfill Symbol for ES5 compatible engines
@ljharb
Copy link

ljharb commented Apr 5, 2015

The spec requires them to work cross-realm but I'm not sure how engines are doing wrt to that compliance.

Right, I think that i'll have to be a sham. Looks great so far though!

@ljharb
Copy link

ljharb commented Apr 5, 2015

Also, possibly a more reliable test for https://gist.github.com/WebReflection/56d04ccb1e5b0e50c121#file-symbol-js-L5 is if (typeof Symbol === 'function' && typeof Symbol() === 'symbol')?

@WebReflection
Copy link
Author

I think if getOwnPropertySymbols is there we have to assume somebody else either patched upfront or the browser must support Symbol natively. I don't see how that check can improve a sham, since we risk to overwrite other attempts that might be there and work as intended for reasons.

TL;DR I wouldn't go for that check, it's prolix for no advantages.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment