hasOwnProperty HTMLElement Firefox

Lin*_*ndy 6 javascript firefox hasownproperty

朋友们,

我注意到在Firefox v23.0.1中,hasOwnPropertyHTMLElement(input,button..etc)不起作用,

button1.hasOwnProperty('id') = false
Run Code Online (Sandbox Code Playgroud)

我用来检查:

 var str1 = '';
        for (pp in button1) {
            if (button1.hasOwnProperty(pp)) {
                str1 += (',' + pp);
            }
        }
        alert(str1);//nothing here
Run Code Online (Sandbox Code Playgroud)

但在chrome hasOwnProperty中效果很好.

你知道这是一个bug吗?

Bor*_*sky 5

根据规范,"id"属性位于HTMLElement.prototype或Element.prototype上(取决于规范版本).

Firefox做对了.Chrome会将所有属性直接放在对象上.


http://dev.w3.org/2006/webapi/WebIDL/#es-attributes http://dev.w3.org/2006/webapi/WebIDL/#ecmascript-binding