闭包是指能够访问自由变量的函数 (变量在本地使用,但在闭包中定义)。换句话说,定义在闭包中的函数可以“记忆”它被创建时候的环境。
function init() {
var name = "Mozilla";
function displayName() {
alert(name);
}
displayName();
}
init();
function init() {
var name = "Mozilla";
function displayName() {
alert(name);
}
displayName();
}
init();
本文标题:JavaScript的闭包
本文链接:https://www.haomeiwen.com/subject/hueajttx.html
网友评论