debouncy

2019-08-14 admin

debouncy是什么

什么是debouncy,yet another debounce implementation with 0 dependencies

debouncy使用教程帮助文档

NPM Version Build Status

debouncy

Yet another debounce implementation with 0 dependencies

Install

npm i --save debouncy

Usage

var debouncy = require('debouncy');

signature

function debouncy(fnToDebounce: Function, threshold:Number, [ctx:Object], [immediate:Boolean]):Function
  • fnToDebounce: Function The function to debounce
  • threshold: Number The number of milliseconds before actually executing the fnToDebounce since the last call to the debounced function.
  • ctx: Object The this object inside the debounced function. If none specified will try to use the ctx of the invocator.
  • immediate: Boolean If true, the function will be executed on the leading edge.

Example

var debouncy = require('debouncy');

var debouncedFn = debouncy(function () { console.log('I am called') }, 200);
debouncedFn();
// after 200ms
// output: I am called
var ctx = {
  name: 'some obj';
}
var debouncedFn = debouncy(function () { console.log('I am called from', this.name) }, 200, ctx);
debouncedFn();
// after 200ms
// output: I am called from some obj

var debouncedFn = debouncy(function () { console.log('I am called') }, 200, null, true /*immediate*/);
debouncedFn();
// immediately
// output: I am called
// other calls will have to wait 200ms before the last execution

Changelog

changelog

License

MIT

本站文章除注明转载外,均为本站原创或编译。欢迎任何形式的转载,但请务必注明出处。

转载请注明:文章转载自 JavaScript中文网 [https://www.javascriptcn.com]

本文地址:https://www.javascriptcn.com/read-72481.html

文章标题:debouncy

回到顶部