W3C home > Mailing lists > Public > public-script-coord@w3.org > October to December 2013

Re: Top Level Array Generics

From: Boris Zbarsky <bzbarsky@MIT.EDU>
Date: Fri, 08 Nov 2013 13:34:59 -0500
Message-ID: <527D2ED3.3070308@mit.edu>
To: public-script-coord@w3.org
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 
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.

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

This archive was generated by hypermail 2.4.0 : Friday, 17 January 2020 17:14:19 UTC