Re: Top Level Array Generics

On 11/8/13 1:27 PM, David Bruant wrote:
> Le 07/11/2013 08:31, Garrett Smith a écrit :
>> Also, Array.filter is NaN in Chrome.
> ... I don't even... Whoaaa... isNaN(Array.filter) is true in Firefox as
> well...
>
> When you think you've seen it all...

isNaN is a slightly silly test to use in this case.

In Firefox, Array.filter is a Function object.  When you use isNaN, that 
invokes ToNumber() on the argument, which per the table at 
http://people.mozilla.org/~jorendorff/es6-draft.html#sec-tonumber 
invokes ToPrimitive, which lands you at 
http://people.mozilla.org/~jorendorff/es6-draft.html#sec-toprimitive and 
you get to OrdinaryToPrimitive.  This gets the "valueOf" property, which 
in this case is Object.prototype.valueOf, which just returns the object 
itself.  So we keep going, try the "toString" property, which returns a 
string like "function filter() {\n    [native code]\n}" or whatnot. 
Then we call ToNumber() on that string, which of course returns NaN. 
And then isNaN returns true.

In Chrome, Array.filter is undefined.  The table at 
http://people.mozilla.org/~jorendorff/es6-draft.html#sec-tonumber says 
to return NaN, and then isNaN returns true.

-Boris

Received on Friday, 8 November 2013 18:35:28 UTC