@Kaciras @jazzg62 @RedNax 试了一下,确实是这样的: ```js for (let i = 0; i { console.log("Async function executed"); }); } ``` 用循环去调用函数,会在覆盖时自动触发次要垃圾回收 !()[ ]
一个不负责任的优化方案(以能用就行为原则): const message = () => { return new Promise((resolve, reject) => { if (img.complete) { resolve("Image loaded successfully"); return; } const prevOnload = img.onload; img.onload = () => { if (prevOnload) { prevOnload(); } resolve("Image loaded successfully"); // 返回回调函数的结果 }; }); };