-
Notifications
You must be signed in to change notification settings - Fork 23.1k
Description
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].Arraywill returnfalse, becauseArray.prototype !== window.frames[0].Arrayand 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 Objectreturnstrue.
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
- Folder:
en-us/web/javascript/reference/operators/instanceof - MDN URL: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/instanceof
- GitHub URL: https://github.com/mdn/content/blob/main/files/en-us/web/javascript/reference/operators/instanceof/index.html
- Last commit: 2d423bd
- Document last modified: 2021-01-09T13:41:23.000Z