Methods
-
<static> after(fn [, count])
-
创建一个函数,只有在运行count次后,才会执行fn
Parameters:
Name Type Argument Default Description fn
function 目标函数
count
number <optional>
0 预执行次数count,默认为0
Returns:
包装后的函数
- Type
- function
-
<static> before(fn [, count])
-
创建一个基于fn,且被调用不超过count次的函数,在第count次调用时返回结果
Parameters:
Name Type Argument Default Description fn
function 目标函数
count
number <optional>
1 最大调用次数count,默认为1
Returns:
包装后的函数
- Type
- function
-
<static> bind(fn, context)
-
绑定this, 第三个参数之后作为默认参数传递给fn,返回偏函数
Parameters:
Name Type Description fn
fn 原始函数
context
* 传递的this
Returns:
- Type
- function
-
<static> compose(fns)
-
将多个函数组合为一个新函数,上一个函数的输入当做输入传入下一个函数
Parameters:
Name Type Argument Description fns
function <repeatable>
任意数量的函数
Returns:
封装后的wrapper,默认参数为fn
- Type
- function
-
<static> debounce(fn, wait [, immediate])
-
debounce 防跳反, 连续在某一时间间隔(wait)内触发的相同事件只在最后一次触发后回调. 多个事件压缩组合为一个事件并触发. 比如搜索输入框,输入结束时发送一次ajax请求,而不是每次改变内容都发送请求
Parameters:
Name Type Argument Default Description fn
fn 原始函数
wait
number 时间差ms(200-500)
immediate
boolean <optional>
true 默认为true,会在wait时间间隔开始调用回调,否则只在时间结束时调用
Returns:
返回防跳反处理后的函数
- Type
- function
-
<static> delay(fn, wait)
-
类似setTimeout, 等待wait毫秒后调用function, 支持传入参数
Parameters:
Name Type Description fn
fn 原始函数
wait
number 等待时间,单位毫秒ms
Returns:
- Type
- function
-
<static> once(fn)
-
创建一个只能调用一次fn的函数,重复调用没有效果,只会返回第一次执行的结果
Parameters:
Name Type Description fn
function 目标函数
Returns:
包装后的函数
- Type
- function
-
<static> partial(fn, args)
-
预先定义fn参数,返回包含参数的新函数,可用''定义需声明的参数,''不可省略
Parameters:
Name Type Argument Description fn
fn 原始函数
args
* <repeatable>
需要提前声明的参数
Returns:
返回偏函数
- Type
- function
-
<static> simpleThrottle(fn, wait)
-
简易节流器,只支持间隔后调用
Parameters:
Name Type Description fn
fn 原始函数
wait
number 节流时间差ms(200-500)
Returns:
返回节流处理后的函数
- Type
- function
-
<static> throttle(fn, wait [, option])
-
函数节流器,主要用于触发频率高的事件,如resize
Parameters:
Name Type Argument Description fn
fn 原始函数
wait
number 节流时间差ms(200-500)
option
object <optional>
option相关设置
Properties
Name Type Argument Default Description leading
boolean <optional>
true false表示禁用第一次调用
trailing
boolean <optional>
true false表示禁用最后一次调用
Returns:
返回节流处理后的函数
- Type
- function
-
<static> wrap(fn, wrapper)
-
将函数fn封装到函数wrapper里,并把fn作为wrapper第一个参数传入其中
Parameters:
Name Type Description fn
function 需要封装为参数的函数fn
wrapper
function 包裹函数wrapper
Returns:
封装后的wrapper,默认参数为fn
- Type
- function