lmislm / lmislm.github.io

hexo的配置
0 stars 0 forks source link

闭包的一些思考代码 #23

Open lmislm opened 9 months ago

lmislm commented 9 months ago

为什么形成了闭包,如何销毁


const api = async () => {
  let count = 0;
  return async () => {
    count++;
    return { count };
  };
};
const test = async () => {
  const fn = await api();
  return async () => {
    const res = await fn();
    console.log(res, "====");
  };
};
async function test1() {
  const fn = await test();
  fn();
  fn();
  fn();
  fn();
}
test1();