In functional programming languages like Lisp Y combinator is used for recursing anonymous functions. Even though JavaScript is a fully fledged functional programming language, it does not need Y combinator to recurse anonymous functions because JavaScript provides you with the arguments.callee attribute which is a reference to the current function.

A simple piece of code to demonstrate this (From mozilla developer docs):

function makeFactorialFunc() {
  alert('making a factorial function!');
  return function(x) {
    if (x <= 1)
      return 1;
      return x * arguments.callee(x - 1);
    };
}

var result = makeFactorialFunc()(5); // returns 120 (5 * 4 * 3 * 2 * 1)
Advertisements