闭包的常见应用场景 一星如月 2022-04-28 67 阅读1分钟 手写bind 函数科里化 手写防抖节流 手写Iterator 立即执行函数 > > 就是把全局变量放到函数里,避免全局污染 axios/fetch .then的回调 function outerFunction(url) { fetch(url).then(() => { console.log(url) }) } // 即使回调可能在很久之后才执行,而outerFunction已经执行完毕了,.then中的回调依然能访问到outerFunction的url 用that存储外部的this