Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: 新增Promise写法 #15

Open
wants to merge 21 commits into
base: master
Choose a base branch
from
Open
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
feat: 简版throttle
zzyueb committed Sep 5, 2023
commit 94dec6a2819c3516f10e05e88af6a0b6d3d355d5
15 changes: 15 additions & 0 deletions src/throttle.js
Original file line number Diff line number Diff line change
@@ -10,3 +10,18 @@ function throttle(fn, wait) {
}
}
}

// 箭头函数版
const throttleSimple = (cb, wait = 0) => {
let lastTime = 0;

const res = (...args) => {
const now = +new Date();
if (now - lastTime > wait) {
cb(...args);
lastTime = now;
}
};

return res;
};