98b. Yet another Fibonacci function.
In brief: Just another way of calling anonymous function (function that had no name).
This way, even you do a recursive function. The name of function doesn't even leak to global scope!
1st this is (at some point) a fundamental of functional programming, a very interesting programming paradigm. 2nd isn't it fun?
You got confused how the hell on earth an unnamed-function can do recursion, right? Well then if we give it a name (for learning propose, of course).
f = function(arg){return arg+1;}
And we define some function
h = function(func){return func(1) * func(4);}
Then you'll see that
h(f) /* can pass function f (which is unnamed) into 2 place. you can reuse it! */
Now, we need to modify our h
function to be a combinator, which is something that had behavior like
h(f); /* will yield */ f(h, f);
I'll leave the rest for your own fun. Hope you like it!
This is clever. You made JavaScript look like Scheme (or Lisp, if you are more familiar with this). I like that.