前端题一

一:

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);
}

 

posted @ 2020-08-30 18:31  文采呱呱  阅读(60)  评论(0编辑  收藏  举报