一个函数只执行一次
function countAdd(fn){
let result;
return function(){
if(fn){
result = fn.call(this,arguments)
fn = null
}
return result
}
}
var countPrintOne = countAdd(function(){
console.log(222)
})
countPrintOne()
countPrintOne()
闭包实现变量累加
function numAdd(){
let a =0;
return function(){
console.log(a++)
}
}
let num = numAdd()
num()
num()
num()