Array detection (was Re: Final iterator spec)

classic Classic list List threaded Threaded
4 messages Options
Reply | Threaded
Open this post in threaded view
|

Array detection (was Re: Final iterator spec)

Peter van der Zee
> Peter van der Zee <[hidden email]> wrote:
>
>>On Sun, Mar 2, 2014 at 4:18 AM, Domenic Denicola
>><[hidden email]> 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 <[hidden email]> 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.

- peter
_______________________________________________
es-discuss mailing list
[hidden email]
https://mail.mozilla.org/listinfo/es-discuss
Reply | Threaded
Open this post in threaded view
|

Re: Array detection (was Re: Final iterator spec)

Allen Wirfs-Brock

On Mar 2, 2014, at 9:04 AM, Peter van der Zee wrote:

>> Peter van der Zee <[hidden email]> wrote:
>>
>>> On Sun, Mar 2, 2014 at 4:18 AM, Domenic Denicola
>>> <[hidden email]> 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 <[hidden email]> 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

_______________________________________________
es-discuss mailing list
[hidden email]
https://mail.mozilla.org/listinfo/es-discuss
Reply | Threaded
Open this post in threaded view
|

Re: Array detection (was Re: Final iterator spec)

Peter van der Zee
> 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.

Okay cool. Is there merit in consistency for this? Iterators getting
an `isIterator()` method perhaps?

- peter
_______________________________________________
es-discuss mailing list
[hidden email]
https://mail.mozilla.org/listinfo/es-discuss
Reply | Threaded
Open this post in threaded view
|

Re: Array detection (was Re: Final iterator spec)

Allen Wirfs-Brock

On Mar 2, 2014, at 10:58 AM, Peter van der Zee wrote:

>> 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.
>
> Okay cool. Is there merit in consistency for this? Iterators getting
> an `isIterator()` method perhaps?

They're really different kinds of tests at a low very. Plus, there is not Iterator object to hang such a method off of.

Allen

_______________________________________________
es-discuss mailing list
[hidden email]
https://mail.mozilla.org/listinfo/es-discuss