On Jan 10, 4:37 pm, Jake Verbaten <rayn...@gmail.com> wrote:
> On Tue, Jan 10, 2012 at 2:41 PM, Scott Sauyet <scott.sau...@gmail.com>wrote:
>
> > gamera  wrote:
> > > hj wrote:
> > >> I *REALLY* don't understand the concern about performance. Do you need
[snip]
> > > i would say the opposite: for long term maintainability,
> > > is better to not rely on a third party library to perform such
> > > a simple task. Also, we should use more ES5, since
> > > also m$ endorsed it, writing polyfills when/if necessary.
>
> > I'm not sure why Microsoft's endorsement should make a difference.  We
> > know their history with standards bodies.
>
> > > var nodes = document.querySelectorAll('#x tr.zebra')
> > > ,   i = 0
> > > ,   node
>
> > > while ( node = nodes[ i++ ] )
> > >    node.classList.remove('zebra')
>
> > So what do you suggest to polyfill querySelectorAll?  It seems to me
> > that if you introduce a substantive QSA polyfill, you're already
> > relying on a large library for this simple task.
>
> You're relying on a large library for the _completely non trivial_ task of
> legacy browser support.
>
> It's valid to conditionally include large shims for older browsers (IE<9)
> and use a well defined subset for modern browsers.

I'm not sure if you meant to say _completely trivial_ or _non-
trivial_; but
in this case, I'd agree that the given problem is relatively trivial
to
implement using a simple all-browser solution:

The original jQuery line of code:

    $('#x tr.zebra').removeClass('zebra');

can be done as (this is completely untested so forgive any mistakes :)

    var xElm = document.getElementById('x')
       ,trList = xElm ? xElm.getElementsByTagName('tr') : [];
    for (var i=trList.length-1; i>=0; i--) {
        var trElm = trList[i];
        trElm.className = (' ' + trElm.className + ' ').replace(/\s
+zebra\s+/g,'').replace(/^\s+|\s+$/g,'');
    }

Some points:

    1) If jQuery was included *ONLY* to avoid the above 6 lines of
code, then learn the basic DOM API and save your webpage some extra
weight.
    2) If jQuery is used/required(?) for other uses on the page, then
it's totally legitimate to use it whereever it makes your intent more
clear. One of jQuery's most compelling features is its ability to
express intent in very few lines of code.
    3) To repeat my original point, to those concerned about how
poorly either of those solutions performs: unless this code happens
*thousands* of times within a loop, your concern seems misplaced. The
performance gained by replacing a few lines of jQuery with several
lines of highly optimized (?) code is lost many times over when you
have to maintain it a couple of months later.

--

hj

-- 
To view archived discussions from the original JSMentors Mailman list: 
http://www.mail-archive.com/jsmentors@jsmentors.com/

To search via a non-Google archive, visit here: 
http://www.mail-archive.com/jsmentors@googlegroups.com/

To unsubscribe from this group, send email to
jsmentors+unsubscr...@googlegroups.com

Reply via email to