Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How does Symbol.hasInstance + instanceof work (or does it even work?) in IE11 and below? #6210

Closed
trusktr opened this issue Sep 7, 2017 · 12 comments · Fixed by #6257
Closed
Labels
claimed good first issue outdated A closed issue/PR that is archived due to age. Recommended to make a new issue

Comments

@trusktr
Copy link

trusktr commented Sep 7, 2017

I'm looking at this output in the repl.

From what I can tell, it requires a Symbol.hasInstance polyfill.

However, the instanceof check isn't being transpiled into anything.

So, in an older browser like IE 10, how can this possibly work if the native instanceof operator will not know to look for Symbol.hasInstance on a constructor?

In otherwords, doesn't

f instanceof Foo;

need to be transpiled to something like

__instanceOf(f, Foo);

where __instanceOf is a helper that can use Symbol.hasInstance (polyfilled or not)?

@babel-bot
Copy link
Collaborator

Hey @trusktr! We really appreciate you taking the time to report an issue. The collaborators
on this project attempt to help as many people as possible, but we're a limited number of volunteers,
so it's possible this won't be addressed swiftly.

If you need any help, or just have general Babel or JavaScript questions, we have a vibrant Slack
community that typically always has someone willing to help. You can sign-up here
for an invite.

@jridgewell
Copy link
Member

Does babel-polyfill not handle this?

@zloirock
Copy link
Member

@jridgewell core-js provide only Symbol.hasInstance and Function.prototype.@@hasInstance, but can't override instanceof operator logic.

@nicolo-ribaudo
Copy link
Member

This is handled by the babel-plugin-transform-es2015-instanceof plugin. It needs to be added to babel-preset-es2015 and babel-preset-env

@ajaymathur
Copy link
Contributor

Hi, Can I take this up please?

@loganfsmyth
Copy link
Member

This is an interesting one. I wonder if it was left out on purpose? I could see this being a performance issue, but I honestly don't know. Seems like we'd need to dig into the git history?

@ajaymathur
Copy link
Contributor

ajaymathur commented Sep 11, 2017

@loganfsmyth I did a search on git log and found following commit:

commit a9ac3b0
Author: Sebastian McKenzie sebmck@gmail.com
Date: Tue Nov 3 19:22:51 2015 +0000

move instanceof functionality to separate plugin - fixes #2745

direct link to issue #2745

@jridgewell
Copy link
Member

Likely just an oversight then, I don't see it being any more of a penalty than typeof.

@matiasfha
Copy link

So this is basically re-add the functionality to preset-env preset-es2015 as mentioned in #6210 (comment)

@jridgewell
Copy link
Member

Yup.

@ajaymathur
Copy link
Contributor

Cool, so can I please take this up ?

@nicolo-ribaudo
Copy link
Member

@ajaymathur Yes 👍

@lock lock bot added the outdated A closed issue/PR that is archived due to age. Recommended to make a new issue label May 4, 2018
@lock lock bot locked as resolved and limited conversation to collaborators May 4, 2018
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
claimed good first issue outdated A closed issue/PR that is archived due to age. Recommended to make a new issue
Projects
None yet
Development

Successfully merging a pull request may close this issue.

8 participants