Hacker Newsnew | past | comments | ask | show | jobs | submitlogin

A function can reference itself without defining the name twice. These both work just fine:

    var factorial1 = function(n) { return n < 1 ? 1 : n * factorial1(n-1) }
    
    function factorial2(n) { return n < 1 ? 1 : n * factorial2(n-1) }


Recursive functions like this are more like closures and not pure functions. Aliasing factorial1 and reassigning it will break the recursion [1]. Maybe this is what jbrooksuk was referring to.

[1] https://leanpub.com/javascript-allonge/read#recursive




Consider applying for YC's Summer 2026 batch! Applications are open till May 4

Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: