Skip to content

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

@jakseb

Description

@jakseb

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

Metadata

Metadata

Labels

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions