News for hackers. Stuff that matters.
Re:From jQuery to JavaScript and back again by jacobr on Friday February 08, 2013 @07:53AM (#5187582)
To just make the DOM API's a little cleaner is so simple in a language like JavaScript, why not just create the abstractions as you need them?

This is not something you should use in production, but just a quick example:

    function setAttr (attr, val) {
      return function (elem) { elem.setAttribute(attr, val); };
    }
    NodeList.prototype.forEach = Array.prototype.forEach;
    var $ = document.querySelectorAll.bind(document);

    $('.foo').forEach(setAttr('foo', 'bar'));
Re:From jQuery to JavaScript and back again by masklinn on Friday February 08, 2013 @08:57AM (#5187830)
> This is not something you should use in production, but just a quick example:

Your quick example is risky and likely broken to all MSIE <= 8: https://developer.mozilla.org/en-US/docs/DOM/NodeList#Why_ca...

Re:From jQuery to JavaScript and back again by mattmanser on Friday February 08, 2013 @09:14AM (#5187925)
There's no forEach in IE8.
Re:From jQuery to JavaScript and back again by jdavis703 on Friday February 08, 2013 @08:50AM (#5187800)
JQuery is slowly moving in that direction [0] and YUI has long let you pick and choose which "abstractions" you need [1].

[0] https://github.com/jquery/jquery/blob/master/README.md [1] http://yuilibrary.com/yui/configurator/

[edited with better link to JQuery build documentation]