閉包是函數(shù)退出后矩距,閉包還能保留對局部函數(shù)變量的引用
閉包例子
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);
閉包是函數(shù)退出后矩距,閉包還能保留對局部函數(shù)變量的引用
閉包例子
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);