开发者

Document Object Model Prototypes in IE8 and IE9

开发者 https://www.devze.com 2023-02-21 23:21 出处:网络
I read a post about Document Object Model Prototypes. While this post is very interes开发者_如何学运维ting and written very well, it seems to me that the actual content of this post is not true in rea

I read a post about Document Object Model Prototypes. While this post is very interes开发者_如何学运维ting and written very well, it seems to me that the actual content of this post is not true in reality. For example the following code:

var div = document.createElement("div");
alert(div.constructor);

Alerts [object HTMLDivElement] on FireFox (and similar message on Chrome) but on IE(8 and 9) it alerts undefined. I also tried to copy/paste the code snippet from the post itself and they failed to run. Did I miss anything ?


It's undefined behaviour.

The .constructor property is bound the JavaScript .prototype. It seems that FireFox and chrome have DOM elements inherit through JavaScript prototypes where as IE just creates an element internally.

There isn't a solid specification on whether the div element returned from .createElement should inherit through prototypes. You shouldn't make any assumption about the inheritance chain of DOM nodes because it's completely browser dependant.

0

精彩评论

暂无评论...
验证码 换一张
取 消