嵌套函数的意外输出

时间:2018-05-24 14:59:56

标签: function nested closures

我正在研究Mozilla tutorial on JavaScript, "Nested functions and closures"

我有这个功能:

function outside(x){
    function inside(y){
        return x + y;
    }
    return inside;
}

这应该返回8:

fn_inside = outside(3);
result = fn_inside(5);
result1 = outside(3)(5);
console.log(result); 

但它返回10 - 为什么会这样?

0 个答案:

没有答案