Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

feat(feature): add throttle function to limt function calls within a ... #259

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

Merged
technoph1le merged 3 commits into quicksnip-dev:main from WizardOfDigits:main
Mar 2, 2025
Merged
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
Next Next commit
feat(feature): add throttle function to limt function calls within a ...
...specified time frame
  • Loading branch information
WizardOfDigits committed Feb 10, 2025
commit 13f8243cd0f9a5202d11715b267e43b270dce468
25 changes: 25 additions & 0 deletions snippets/javascript/function-utilities/throttle-function.md
View file Open in desktop
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
---
title: Throttle Function
description: Ensures a function is only called at most once in a specified time interval. Useful for optimizing events like scrolling or resizing.
author: WizardOfDigits
tags: throttle,performance,optimization
---

```js
const throttle = (func, limit) => {
let inThrottle;
return (...args) => {
if (!inThrottle) {
func(...args);
inThrottle = true;
setTimeout(() => (inThrottle = false), limit);
}
};
};

// Usage:
const logScroll = throttle(() => console.log("Scroll event triggered"), 1000);

// Attach to scroll event
window.addEventListener("scroll", logScroll);
```

AltStyle によって変換されたページ (->オリジナル) /