Extra functions on Arrays, Maps, etc..

Rick Waldron waldron.rick at gmail.com
Sat Apr 7 17:28:07 PDT 2012


On Sat, Apr 7, 2012 at 8:24 PM, Erik Arvidsson <erik.arvidsson at gmail.com>wrote:

> On Sat, Apr 7, 2012 at 16:40, Rick Waldron <waldron.rick at gmail.com> wrote:
> >> var arr = document.getElementsByTagName("a");
> >> var externalElms = arr.filter(function(acc, item) {
> >> (/^https?:\/\//).test(item.href) });
> >>
> >> Or,
> >>
> >> var arr = document.querySelector("div")
> >> var divMap = arr.fold(new Map, function(acc, item) { acc.add(item.id,
> >> item); });
> >
> >
> > Nit: You'd still need to convert the NodeList into an array before using
> any
> > Array methods
>
> FYI
>
> DOM4 specs NodeList as an ArrayClass. This will be in ToT WebKit next
> week. Enjoy :-)
>
> http://www.w3.org/TR/2012/WD-dom-20120405/#interface-nodelist
> http://dev.w3.org/2006/webapi/WebIDL/#ArrayClass
> https://bugs.webkit.org/show_bug.cgi?id=81573
>
>
As in, its [[Class]] is "Array" and Array.isArray( nodes ) would evaluate
to true?

Rick



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


More information about the es-discuss mailing list