Re: typeof document.all

Ian Hickson wrote:
>On Fri, 19 Jun 2009, Thomas Broyer wrote:
>>  - Opera and FF return false for document.hasOwnProperty("all"); this
>> is inconsistent with the above, given that document.prototype is null
>> (the property exists according to [[HasProperty]], it cannot be in the
>> prototype chain as there is not prototype, but it doesn't exist on the
>> object, so where is it?!) Chrome and Safari return true.
> 
> I've gone with the Chrome/Safari behaviour here.

I'm confused by this.  In Gecko, document.all is in fact on the 
prototype of the document.  More precisely, trying to use document.all 
(as opposed to just test for it) changes the prototype chain of the 
document such that its prototype has the "all" property.  Try this in 
your favorite Gecko-based browser:

<script>
   var oldProto = document.__proto__;
   alert(oldProto.hasOwnProperty("all"));
   document.all.length;
   alert(oldProto.hasOwnProperty("all"));
   alert(document.__proto__.hasOwnProperty("all"));
   alert(document.__proto__ == oldProto);
   alert(document.__proto__.__proto__ == oldProto);
</script>

You should be seeing alerts with the following values:
false, false, true, false, true

I have no idea what the spec is saying about this, exactly (link 
appreciated), but document.hasOwnProperty("all") is false in Gecko, and 
will continue to be so, I suspect; that's just not an own property of 
that object.  The behavior is quite self-consistent, contrary to Thomas' 
claim above.

-Boris

Received on Tuesday, 14 July 2009 05:57:04 UTC