Extra functions on Arrays, Maps, etc..

Erik Arvidsson erik.arvidsson at gmail.com
Sat Apr 7 17:24:35 PDT 2012


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

-- 
erik


More information about the es-discuss mailing list