var s2 = function (h) { return function (n) { // inner function return n === 1 ? 1 : n + h(h)(n - 1); }; }; console.assert(s2(s2)(5) === 15);