Syntax of Closures

前端 未结 3 1958
我在风中等你
我在风中等你 2021-01-19 04:28
function makeIncreaseByFunction(increaseByAmount) {
  return function (numberToIncrease) {
    return numberToIncrease + increaseByAmount;
  };
}

makeIncreaseByFunc         


        
3条回答
  •  囚心锁ツ
    2021-01-19 05:08

    var increaseBy3 = makeIncreaseByFunction(3); is the exact same as (disregarding the local storage for the variable increaseByAmount):

    var increaseBy3 = function (numberToIncrease) {
        return numberToIncrease + 3;
    };
    

    So of course now you can call increaseBy3(10) and get 13. increaseBy3 just references as anonymous function which returns its first argument plus 3.

提交回复
热议问题