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

The instanceof Operator #398

Open
futurfrukt opened this issue Jan 25, 2021 · 0 comments
Open

The instanceof Operator #398

futurfrukt opened this issue Jan 25, 2021 · 0 comments

Comments

@futurfrukt
Copy link

futurfrukt commented Jan 25, 2021

The instanceof operator compares the constructors of its two operands

This is a bit misformulated and can be wrong understood: according to MDN, instanceof compares not constructor (property of prototype object, but the exact link to prototype objects.

If you set only constructor property, the instanceof will return false, because despite prototype objects looks equal, they are actually different objects:

function A(){}
function B(){}
B.prototype.constructor = A; // *

// has the same constructor 
B.prototype.constructor === A; // true

// but this does not mean its an instance of
new B() instanceof A; // false
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant