本文介绍了无法在Firefox中读取Element.prototype的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如果我运行这个javascript:

  var a,b = Element.prototype; 
for(a in b)b [a];

Firefox给我这个错误:

  TypeError:Value不实现接口元素。 

这是一个测试用例:



其它浏览器。我如何使它在Firefox中工作?这是驱使我坚果!
解决方案

Firefox(和最近的IE)行为在这里是因为属性获取一些属性(比如说 firstChild )在原型对象bu上,这些属性对原型本身没有任何意义。尝试让它们在原型上会抛出。



事实上,这是规范所要求的行为。请参阅步骤2子步骤2​​ subsubstep 2. Firefox和IE在这里遵循这个规范,而基于WebKit的浏览器则不是这样。


If I run this javascript:

var a,b=Element.prototype;
for(a in b)b[a];

Firefox gives me this error:

TypeError: Value does not implement interface Element.

Here is a test case:http://codepen.io/WilliamMalo/pen/AJkuE

It works in all other browsers. How can I make it work in firefox? It's driving me nuts!

解决方案

The Firefox (and recent IE) behavior here is because the property getters for some properties (say firstChild) are on the prototype object bu the properties make no sense on the prototype itself. Trying to get them on the prototype will throw.

This is the behavior required by the specification, in fact. See http://dev.w3.org/2006/webapi/WebIDL/#dfn-attribute-getter step 2 substep 2 subsubstep 2. Firefox and IE are following the spec here and WebKit-based browsers are not.

这篇关于无法在Firefox中读取Element.prototype的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

11-01 01:49