闭包是函数退出后,闭包还能保留对局部函数变量的引用
闭包例子
function funs(){
this.inc=1;
function a(){this.inc++};
function b(){this.inc--};
return [a,b];
}
var f = funs();
console.log(inc);
let f0 = f[0];
f0();
console.log(inc);
闭包是函数退出后,闭包还能保留对局部函数变量的引用
闭包例子
function funs(){
this.inc=1;
function a(){this.inc++};
function b(){this.inc--};
return [a,b];
}
var f = funs();
console.log(inc);
let f0 = f[0];
f0();
console.log(inc);
本文标题:闭包
本文链接:https://www.haomeiwen.com/subject/rkkcrktx.html
网友评论