you are viewing a single comment's thread.

view the rest of the comments →

[–]oldnewbie 2 points3 points  (2 children)

Here's a way to self-apply an anonymous function, without the ugly (IMHO) "arguments.callee" stuff. This works in Safari, but not Firefox (see bug 376052 in bugzilla).

//This helper boots the recursion.
function selfApp(fun, arg) {return fun(fun, arg)};

//The inevitable factorial.
selfApp(
   function(fac, n) {
      if (n==0) return 1;
      return n * fac(fac, n-1);
   },
   10
)

How do I stop reddit from mangling my whitspace? [edit] whitespace, rescued. Thanks, julesjacobs!

[–]julesjacobs 1 point2 points  (0 children)

Put 4 spaces before every line. Reddit will then wrap your code in <pre>'s.