Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Restrict how frequently a function may be invoked.
JavaScript
branch: master

Fetching latest commit…

Cannot retrieve the latest commit at this time

Failed to load latest commit information.
example
.gitignore
History.md
LICENSE
Makefile
Readme.md
component.json
index.js

Readme.md

throttle

Restrict how frequently a function may be invoked.

Note:

The original implemenation comes from underscore, except just to be a pain, I've flipped the argument order so the function always comes last. This is to prevent hard to read, dangling arguments when using anonymous functions or long function invocations, such as when using bind.

Plans: Dump confusing underscore implementation + implement fluent interface. Interface very likely to change.

Installation

$ component install timoxley/throttle

Example

  var throttle = require('throttle')
  window.addEventListener('scroll', throttle(1000, function() {
    console.log('I should only happen once every second.')
  }))
  window.addEventListener('scroll', throttle(2000, function() {
    console.log('I should only happen once every two seconds.')
  }))

API

throttle(wait, fn)

Returns a new function that wraps the supplied fn, blocking calls to fn until wait milliseconds have elapsed.

throttle.debounce(wait, immediate, fn)

Returns a function, that, as long as it continues to be invoked, will not be triggered. The function will be called after it stops being called for wait milliseconds.

License

MIT

Something went wrong with that request. Please try again.