小编use*_*358的帖子

Javascript关闭函数参数?

代码属于javascriptissexy.com我的问题是为什么调用mjName("杰克逊")返回"这个名人是迈克尔·杰克逊"?是不是在任何外部函数中给出的第二个参数,对js =内部函数参数说?有人能详细解释整个概念吗?

function celebrityName (firstName) {
    var nameIntro = "This celebrity is ";
// this inner function has access to the outer function's variables, including the parameter
    function lastName (theLastName) {
        return nameIntro + firstName + " " + theLastName;
    }
    return lastName;
}

var mjName = celebrityName ("Michael");
    // At this juncture, the celebrityName outer function has returned.

// The closure (lastName) is called here after the outer function has returned above
// Yet, the closure still has access …
Run Code Online (Sandbox Code Playgroud)

javascript closures

6
推荐指数
2
解决办法
1万
查看次数

标签 统计

closures ×1

javascript ×1