javascript - In js, where do the properties and methods of the dom object inherit from?
PHP中文网
PHP中文网 2017-06-26 10:53:16
0
3
803
var dom = document.getElementById('domId');
dom.innerHTML = "hello world!";
console.log(typeof dom); //object
console.log(dom.hasOwnProperty("innerHTML")); //false
console.log(dom.__proto__.hasOwnProperty("innerHTML")); //false
PHP中文网
PHP中文网

认证高级PHP讲师

reply all(3)
世界只因有你

typeof can only roughly identify object or other basic data types. You might as well try toString. I have seen some framework js and check the object type through toString. Perform string processing on the result to get the type name. .

You can check related content in mdn, such as p’s dom type https://developer.mozilla.org...

You can see its main inheritance relationship.

For example innerHTML, actually here https://developer.mozilla.org...
Attributes of the Element class

滿天的星座


As you can see from the picture above, HTML elements have corresponding interfaces, which are part of javasript. Please refer to MDN
https://developer.mozilla.org...

滿天的星座

The prototype chain is HTMLpElement -> HTMLELement -> Element -> Node -> EventTarget
but innerHTML cannot be used directly on them,

The innerHTML assignment/retrieval of dom is definitely not assigned/retrieved directly on the prototype chain. It is probably implemented by some internal methods, so the above string of .hasOwnProperty('innerHTML') are all false.

Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!