Extra functions on Arrays, Maps, etc..

Rick Waldron waldron.rick at gmail.com
Sat Apr 7 17:49:35 PDT 2012


On Sat, Apr 7, 2012 at 8:41 PM, Domenic Denicola <
domenic at domenicdenicola.com> wrote:

>  On Apr 7, 2012, at 20:37, "Rick Waldron" <waldron.rick at gmail.com> wrote:
>
>   On Sat, Apr 7, 2012 at 8:31 PM, Erik Arvidsson <erik.arvidsson at gmail.com
> > wrote:
>
>> On Sat, Apr 7, 2012 at 17:28, Rick Waldron <waldron.rick at gmail.com>
>> wrote:
>> > As in, its [[Class]] is "Array" and Array.isArray( nodes ) would
>> evaluate to
>> > true?
>>
>>  No, it means that Object.getPrototypeOf(NodeList.prototype) ===
>> Array.prototype.
>>
>
>  Yes, this part was clear in the links you sent. The question I had was
> about two things that were not addressed in the links (that I could see,
> please correct if I missed them)
>
>  There will be much confusion on the web if Array.isArray(nodes) returns
> false, while nodes.push( node ), nodes.slice( 0, 2 ) "just work",
> especially during periods of transition from DOMx to DOM4.
>
>
>  Rick
>
>
>
>> Fortunately all the Array.prototype methods are generic so it all just
>> works.
>>
>> --
>> erik
>>
>
>
> I think the benefits are so great I'm happy to deal with any confusion.
>

>  Although, it sounds like I'll be wanting to go back to `instanceof
> Array`, which is kind of funny.
>

`instanceof Array` is unreliable across contexts (ie. frames) whereas
Object.prototype.toString.call( thing ) === "[object Array]" is
irrefutable...  That said, I'm sure there is also plenty of code that that
still expects Object.prototype.toString.call( nodelist ) === "[object
NodeList]" (as unadvisable as that might be)


Rick
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.mozilla.org/pipermail/es-discuss/attachments/20120407/8f875916/attachment.html>


More information about the es-discuss mailing list