News for hackers. Stuff that matters.
Re:JavaScript closures and recursion by tlrobinson on Thursday November 25, 2010 @03:01PM (#1940900)
I'm sorry, what's so special about this bit of code?

It doesn't seem very interesting unless you weren't aware of JavaScript's functional nature, and it's actually more complicated than it needs to be, unless I'm missing something. Here's how I'd do it:

    function startSlideshow(ms) {
        var index = -1;
        var count = $(".change_link").length - 1;
        return setInterval(function() {
            index = (index + 1) % count;
            $('.slideshow').blinds_change(index);
        }, ms);
    }
Re:JavaScript closures and recursion by synx508 on Thursday November 25, 2010 @03:56PM (#1940984)
I was also rather confused as to what I was supposed to be looking at and why it wasn't using setInterval.

Your script is nicer, the modulo and increment in the same line is very tidy. It's not hacker news though, is it, or am I missing something?

Re:JavaScript closures and recursion by ecounysis on Thursday November 25, 2010 @11:48PM (#1941654)
I like the use of modulo; I hadn't thought of that.

setInterval is definitely much more simple and clean than recursively calling setTimeout, however it doesn't illustrate what is going on under the hood or how setInterval might be implemented.

Writing a Y-combinator isn't the easiest way to write a recursive function, but it does help us learn how recursion really works.