一:
function debounce(fn, delay = 0) {
let timer = null;
const debounceFn = function () {
if (timer) {
clearTimeout(timer);
}
new Promise((resolve) => {
resolve();
timer = setTimeout(() => {
fn.apply(this);
}, delay);
}).then(() => {
timer = null;
});
};
return debounceFn;
}
二:promise是什么?
三:以下题目会输出什么?
let i;
for (i = 0; i < 3; i++) {
const log = () => {
console.log(i);
}
setTimeout(log, 1000);
}