Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.javascript > #31094

Re: filter queryselectorall

Newsgroups comp.lang.javascript
Date 2016-08-07 10:30 -0700
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> <1546201.XMfzL8yDUt@PointedEars.de>
Message-ID <792aba7d-dad5-48f2-abbc-08beaf9a69ad@googlegroups.com> (permalink)
Subject Re: filter queryselectorall
From "Michael Haufe (TNO)" <tno@thenewobjective.com>

Show all headers | View raw


On Sunday, August 7, 2016 at 12:08:43 AM UTC-5, Thomas 'PointedEars' Lahn wrote:
> 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?

The common habit is to write JavaScript to target the least common denominator of support: namely ES3 or ES5. Hence my example and more-so yours. I take the position that one should write in the latest standard version and compile to the lowest common denominator instead. Web Developers aren't quite there yet in their personal workflow though and many common libs may not be prepared properly for use (using global variables and fake namespaces vs. modules).


> 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.)

I would rather defer to Array.from, but yes, if I wanted to micro-optize:

var filter = (xs,fn) => Array.prototype.filter.call(xs,fn)
var isEven = (x) => x % 2 == 0
var xs = [1,2,3,4,5]
filter(xs,isEven)
/* 2,4 */

Even better if the standards bodies would align better and fix this mess of an inheritance model.

NodeList extends Array or somesuch...

Back to comp.lang.javascript | Previous | NextPrevious in thread | Next in thread | Find similar | Unroll thread


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