Content: Various issues with "instanceof": a weird claim, typos...

Created on 20 Feb 2021  ·  3Comments  ·  Source: mdn/content

MDN URL: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/instanceof

Description > instanceof and multiple context (e.g. frames or windows)

For instance, [] instanceof window.frames[0].Array will return false, because Array.prototype !== window.frames[0].Array and arrays inherit from the former.

I believe the inequality should be Array.prototype !== window.frames[0].Array.prototype. In addition, 'arrays' alone might suggest that all arrays inherit from Array.prototype, including those from frames[0]. I think that needs to be clarified, e.g. 'arrays created in the current context'.

For example, checking if a Nodes is a SVGElement in a different context, you can use myNode instanceof myNode.ownerDocument.defaultView.SVGElement.

It should be 'Node', not 'Nodes'.

Examples > Demonstrating that String and Date are of type Object and exceptional cases

However, objects created with the object literal notation are an exception here: Although the prototype is undefined, instanceof Object returns true.

It is not true that the prototype is undefined. It's Object.prototype, which is even stated in the code that follows. Thus, there's nothing exceptional here. I think the paragraph quoted above should be removed and some adjustments should be made to the rest of the section (including its title).

Other

Maybe it might be a good idea to mention shortly the role of Symbol.hasInstance?



MDN Content page report details

30 minute task JS

Most helpful comment

Happy to let you give it a go; thanks a lot for all your enthusiasm, @CreaTorAlexander !

All 3 comments

I can update this 👍

Happy to let you give it a go; thanks a lot for all your enthusiasm, @CreaTorAlexander !

@chrisdavidmills I enjoy contributing to mdn/content 😄

Was this page helpful?
0 / 5 - 0 ratings

Related issues

ydaniv picture ydaniv  ·  4Comments

vinyldarkscratch picture vinyldarkscratch  ·  4Comments

lychyi picture lychyi  ·  3Comments

sideshowbarker picture sideshowbarker  ·  3Comments

arturcarvalho picture arturcarvalho  ·  5Comments