我不知道为什么Element instanceof Node
返回false,因为nodeType为1的任何元素都是特殊类型的节点。为什么`Element instanceof Node`返回false
以下是我从MDN发现:
以下接口都从节点继承其方法和属性:文档,元素,CharacterData(该文本,注释和CDATASection的继承)的ProcessingInstruction,DocumentFragment的,DocumentType,符号,实体的EntityReference
而且问题2:为什么在DOM任何元素既是instanceof的元素和instanceof的Node.The代码如下:
var div = document.querySelector("div");
div instanceof Node;//true
div instanceof Element;//true
Element instancof Node;//false
因为'instanceof'测试是否某物是**实例**。 'Element'不是一个实例。这是一个构造函数。 – Li357
'Element instanceof Function'将成立。要检查类是否相互继承,请参见[here](http:// stackoverflow。com/a/35921495/1048572) – Bergi
请注意,浏览器不一定要实现原型继承。 – RobG