我們常使用nodeType==1來判斷元素是否為HMTLElement元素。頁面上的元素都是節點(Node),有元素節點(Element Node)、屬性節點(Attribute Node)、文字節點(Text Node)等。 w3c nodeType 的定義如下
const unsigned short ELEMENT_NODE = 1;
const unsigned short ATTRIBUTE_NODE = 2;
const unsigned short TEXT_NODE = 3;
const unsigned-constd unsigned [ATA_Ft. _NODE = 5;
const unsigned short ENTITY_NODE = 6;
const unsigned short PROCESSING_INSTRUCTION_NODE = 7;
const unsigned short COMMENT_NODE = 8; DOC_o>g; PE_NODE = 10;
const unsigned short DOCUMENT_FRAGMENT_NODE = 11;
const unsigned short NOTATION_NODE = 12;
但如果我們自訂的物件也包含nodeType屬性呢?如