what is the lexical environment of a function argument?

前端 未结 3 1094
深忆病人
深忆病人 2021-01-27 23:06

Javascript supports First Class Functions, in which case we can pass the function as an argument. An anonymous function that is defined inside an argument list of another functi

3条回答
  •  没有蜡笔的小新
    2021-01-27 23:44

    When you're unsure what the scopes of a function defined in the arguments list of a call is, notice that

    fn(function x(…) { … })
    

    is equivalent to

    _temp = function x(…) { … };
    fn(_temp)
    

    Arguments are evaluated before the actual call, and they're evaluated in the same scope as the call itself is evaluated in.

提交回复
热议问题