函数节流控制
- Description:
函数节流控制
- Source:
Methods
(static) debounce(fn, $optopt) → {function|function}
- Description:
按指定间隔时间内的调用将延迟指定时间后执行
- Source:
Example
// 1.默认延迟时间500ms
let fn = debounce(your_function,{instant:false,delay:1500});
Parameters:
Name | Type | Attributes | Description |
---|---|---|---|
fn |
function | 要执行的函数 |
|
$opt |
Object |
<optional> |
|
$opt.delay |
Number |
<optional> |
延迟时间 |
$opt.leave |
Boolean |
<optional> |
是否保留最后一次调用 |
$opt.instant |
Boolean |
<optional> |
是否立即执行 默认false |
Returns:
-
ret - 被包装的函数
- Type
- function
-
ret.clear - 清除延迟调用
- Type
- function
(static) throttle(fn, $optopt) → {function|function}
- Description:
按指定时间间隔执行函数
- Source:
Example
// 1.默认延迟时间500ms
let fn = throttle(your_function,{instant:false,delay:1500});
Parameters:
Name | Type | Attributes | Description |
---|---|---|---|
fn |
function | 要执行的函数 |
|
$opt |
object |
<optional> |
|
$opt.delay |
Number |
<optional> |
延迟时间 |
$opt.leave |
Boolean |
<optional> |
是否丢弃指定时间内的请求,true,如果在指定的时间内被调用多次,则全部丢弃;`false',如果在指定的时间内被调用多次,最后一次将被执行 |
Returns:
-
ret - 被包装的函数
- Type
- function
-
ret.clear - 清除延迟调用
- Type
- function