赞
踩
具体可见https://github.com/febobo/web-interview
function fn(){
let count = 0
return function fun(){
count++;
console.log(`函数被调用${count}次`);
}
}
const result = fn()
console.log(result()); //1
console.log(result()); //2
闭包应用:实现数据的私有。如count
不能被全局访问,只能在fun()
中修改。
内存泄露:
手动回收:result = null
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。