I\'m very new to JavaScript, and I was hoping to get some help with Chapter 5 in the 2nd Ed. of Eloquent JavaScript. Specifically, I ran into the example below:
The noisy function takes a single parameter f
which is a function. When you call noisy, it returns a new function (which means noisy(Boolean) returns a function). The capturing takes place because the new function has access to any parameters of noisy, including the f
parameter (programmers call this concept a closure). When you have noisy(Boolean)(1)
the f
inside the inner function is referring to Boolean
. So, val
gets set to Boolean(1)
since var val = f(arg)
.