Eloquent JavaScript, 2nd Edition, Chapter 5 Higher-Order Functions

后端 未结 3 848
心在旅途
心在旅途 2021-01-23 00:48

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:

         


        
3条回答
  •  夕颜
    夕颜 (楼主)
    2021-01-23 01:22

    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).

提交回复
热议问题