Array detection (was Re: Final iterator spec)
Allen Wirfs-Brock
allen at wirfs-brock.com
Sun Mar 2 10:42:16 PST 2014
On Mar 2, 2014, at 9:04 AM, Peter van der Zee wrote:
>> Peter van der Zee <ecma at qfox.nl> wrote:
>>
>>> On Sun, Mar 2, 2014 at 4:18 AM, Domenic Denicola
>>> <domenic at domenicdenicola.com> wrote:
>>>> You can just do `if (Symbol.iterator in potentialIterable)`.
>>>
>>> Does that work cross-frame?
>
> On Sun, Mar 2, 2014 at 5:35 PM, Allen Wirfs-Brock <allen at wirfs-brock.com> wrote:
>> Yes
>
> Okay, was wondering whether that could work for Array detection as
> well. But perhaps that problem has already been solved, I haven't kept
> up with that.
>
> `if (Array[Symbol.isArray]) ...` feels like a fairly elegant cross
> frame solution.
Depends upon what you mean by "Array detection". If you mean is obj an "exotic array object (ie, an object that automatically updates the length property value as integer indexed properties are added or deleted) then Array.isArray(obj) detects exactly that.
Allen
More information about the es-discuss
mailing list