News for hackers. Stuff that matters.
Re:ƒu.js - The Functional DOM traversing library. by masklinn on Sunday January 30, 2011 @07:37AM (#2157929)
> In the author's defence, the Fu.JS syntax is much nicer than the jQuery syntax

How? No, seriously, how is

    ƒ('body').style.background = '#f4f6f8';
much nicer than

    $('body').css('background', '#f4f6f8');
?

    fu().body.fu('ul').appendChild(ƒ().createElement('li'));
than

    $('body ul').append($('<li>'));
?

    document.body.ƒ('ul li:last-child').innerText = "I'M THE NEW GUY!";
than

    $(document.body).find('ul li:last-child').text("I'M THE OLD GUY!");
?

    for (var i=0; i < 50; i++) {
        ƒ('ul').appendChild(ƒ().createElement('li'));
    }
than

    for (var i=0; i<50; ++i) {
        $('ul').append($('<li>'));
    }
?

    ƒ('ul li:nth-child(2n)', 'style.background = "black"')
than

    $('ul li:nth-child(2n)').css('background', 'black')

?
Re:ƒu.js - The Functional DOM traversing library. by jeresig on Sunday January 30, 2011 @09:35AM (#2158106)
Some quickie improvements to the jQuery examples:

    $('body ul').append($('<li>'));
can become:

    $('body ul').append('<li>');
and:

    $(document.body).find('ul li:last-child').text("I'M THE OLD GUY!");
can become:

    $("body").find('ul li:last-child').text("I'M THE OLD GUY!");
(We optimize for body explicitly in our selector code.) Although that last example selector is rather weird, it's equivalent to:

    $("body ul li:last-child")
or even just:

    $("ul li:last-child")
(When is a ul ever going to be outside of a body element?)
Re:ƒu.js - The Functional DOM traversing library. by Sephr on Sunday January 30, 2011 @11:18AM (#2158314)

    document.body.ƒ('ul li:last-child').innerText = "I'M THE NEW GUY!";
That code won't work in standards-compliant browsers. You should either use .textContent = "..." or .appendChild(document.createTextNode("...")) or .firstChild.wholeText = "..." if there's already a text node child.

The real issue though is that unlike jQuery, ƒu.js won't work in popular versions of IE.

Re:ƒu.js - The Functional DOM traversing library. by masklinn on Sunday January 30, 2011 @11:42AM (#2158376)
Well apart from the first one (clearly my mistake) I was trying to translate the original semantics as closely as possible. Hence the repeated (if not very useful) `body` anchors.

> (When is a ul ever going to be outside of a body element?)

Document fragments? XML documents? Not sure you can use that style of jQuery calls on those, but~~

Re:ƒu.js - The Functional DOM traversing library. by Tycho on Sunday January 30, 2011 @11:34AM (#2158355)
well for a start, Fu.js is using straight forward assignment statements with the = sign, whereas in jquery you're passing two arguments into a function without being able to see what they're for or what order they should be in.

some of the fu.js lines are a bit unwieldy but at least it's obvious to me what they do - i found jQuery code pretty bewildering until i delved into it

Re:ƒu.js - The Functional DOM traversing library. by masklinn on Sunday January 30, 2011 @11:47AM (#2158395)
> whereas in jquery you're passing two arguments into a function without being able to see what they're for or what order they should be in.

Unless, of course, you've spent roughly 5mn reading upon how jQuery's getting and setting works. Then you know the first argument is a key and the second one is a value to set.

I can see you've also quickly moved the goalposts, from "fu.js's syntax is much nicer" (emphasis yours) to "I claim to undetstand what fu.js does without having read its documentation"

Re:ƒu.js - The Functional DOM traversing library. by Tycho on Sunday January 30, 2011 @12:58PM (#2158570)
Well in the original examples I responded to, I thought the syntax was considerably nicer, that's what I was commenting on. In the different examples (shifting goalposts...) someone responded to me with, the benefit was less pronounced. In general, jQuery has absolutely horrible syntax (IMO), so I can understand someone building a library to make a few small improvements like normal assignment statements.