Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.javascript > #31091
| From | Thomas 'PointedEars' Lahn <PointedEars@web.de> |
|---|---|
| Newsgroups | comp.lang.javascript |
| Subject | Re: filter queryselectorall |
| Date | 2016-08-07 07:08 +0200 |
| Organization | PointedEars Software (PES) |
| Message-ID | <1546201.XMfzL8yDUt@PointedEars.de> (permalink) |
| References | <b-Cdnanqh8Yn-zjKnZ2dnUU7-RnNnZ2d@westnet.com.au> <e5c7c7d6-59fb-489a-bf33-cea363488a6c@googlegroups.com> <1547678.NO00hCYTYS@PointedEars.de> <a97c4abf-b135-4054-a9b2-55e0190cd1d0@googlegroups.com> |
Michael Haufe (TNO) wrote:
> More like a pin-hammer. This is a general solution to the problem of
> manipulating NodeLists, not solving this particular problem. The
> alternative formulation, to avoid a potential compilation step for
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
How so?
> down-rev environments would be:
>
> function qsa(s,ctx){return
> [].slice.call((ctx||document).querySelectorAll(s))}
>
> But is a more low-level[1] solution.
>
>> Instead:
>>
>> var clickables = [].filter.call(
>> document.querySelectorAll('[id^="clickable_"]'),
>> function (element) { return /_\d+$/.test(element.id); });
>
> Using the form above:
>
> var clickables = qsa('[id^="clickable_"]').filter(e => /_\d+$/.test(e.id))
Yes, but one problem with converting a NodeList into an Array is that
NodeLists are live; Arrays are not. Applying an Array prototype method on a
NodeList directly is guaranteed to iterate over all items if matching items
are added while the loop is running, or not iterated over if they are
removed before iteration has reached them.
Another problem is creating an Array instance unnecessarily. (“[].filter”
is just the short form. Creation of an Array instance before filtering can
be avoided entirely by holding the value of “Array.prototype” or
“Array.prototype.filter” in a variable and re-using it as needed.)
--
PointedEars
FAQ: <http://PointedEars.de/faq> | SVN: <http://PointedEars.de/wsvn/>
Twitter: @PointedEars2 | ES Matrix: <http://PointedEars.de/es-matrix>
Please do not cc me. / Bitte keine Kopien per E-Mail.
Back to comp.lang.javascript | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread
filter queryselectorall Andrew Poulos <ap_prog@hotmail.com> - 2016-08-06 14:25 +1000
Re: filter queryselectorall "Michael Haufe (TNO)" <tno@thenewobjective.com> - 2016-08-05 22:23 -0700
Re: filter queryselectorall Thomas 'PointedEars' Lahn <PointedEars@web.de> - 2016-08-06 08:16 +0200
Re: filter queryselectorall "Michael Haufe (TNO)" <tno@thenewobjective.com> - 2016-08-06 15:49 -0700
Re: filter queryselectorall Thomas 'PointedEars' Lahn <PointedEars@web.de> - 2016-08-07 07:08 +0200
Re: filter queryselectorall Cezary Tomczyk <cezary.tomczyk@gmail.com> - 2016-08-07 07:17 +0200
Re: filter queryselectorall Thomas 'PointedEars' Lahn <PointedEars@web.de> - 2016-08-07 07:58 +0200
Re: filter queryselectorall "Michael Haufe (TNO)" <tno@thenewobjective.com> - 2016-08-07 10:30 -0700
Re: filter queryselectorall Thomas 'PointedEars' Lahn <PointedEars@web.de> - 2016-08-07 21:16 +0200
Re: filter queryselectorall "Michael Haufe (TNO)" <tno@thenewobjective.com> - 2016-08-09 21:18 -0700
Re: filter queryselectorall Thomas 'PointedEars' Lahn <PointedEars@web.de> - 2016-08-15 22:02 +0200
Re: filter queryselectorall "Michael Haufe (TNO)" <tno@thenewobjective.com> - 2016-08-15 23:16 -0700
Re: filter queryselectorall "Evertjan." <exxjxw.hannivoort@inter.nl.net> - 2016-08-06 10:28 +0200
csiph-web