js-throttle-debounce

0.1.1 • Public • Published

js-throttle-debounce

Build Status Coverage Status
NPM
A javascript prototype plugin provides throttle and debounce methods.
This refers to jquery-throttle-debounce

Download

Compress
Uncompress

Installation

You can also install js-throttle-debounce by using Bower.

bower install js-throttle-debounce

For node.js, you can use this command to install:

npm install js-throttle-debounce

Demo

Demo

Usage

You could use like this: JavaScript

function yourMethod() {
  // ...
}
var throttle = yourMethod.throttle();
var throttleIgnoreLast = yourMethod.throttle(500, true);
var debounce = yourMethod.debounce(100);

Methods

Function.throttle([delay], [ignoreLast])

Create a throttle method.

delay: Number (default: 100)

Set delay in milliseconds.

ignoreLast: Boolean (default: false)

Set true that last trigger will not be executed.

Function.debounce([delay])

Create a debounce method.

delay: Number (default: 100)

Set delay in milliseconds.

Example

AJAX Search

HTML

<input type="text" onchange="search()" />

JavaScript

function ajaxSearch() {
  // ... do AJAX search by keyword
}
search = ajaxSearch.debounce();

Resize

JavaScript

function updateLayouts() {
  // ... render something when resizing
}
window.onresize = updateLayouts.throttle();

License

The project is released under the MIT license.

Contact

The project's website is located at https://github.com/emn178/js-throttle-debounce
Author: emn178@gmail.com

Readme

Keywords

Package Sidebar

Install

npm i js-throttle-debounce

Weekly Downloads

117

Version

0.1.1

License

MIT

Last publish

Collaborators

  • emn178