why does this work..
It's also worth noting that functions are first-class objects. You can toss them around like any other object. Here's a nice concise example of why this is cool, from Wikipedia:
function makeDerivative( f, deltaX ) {
var deriv = function(x) {
return ( f(x + deltaX) - f(x) )/ deltaX;
}
return deriv;
}
var cos = makeDerivative( Math.sin, 0.000001);