vtils

Home > utils > bindEvent

bindEvent() function

绑定事件。

Signature:

export declare function bindEvent<T extends Record<'addEventListener' | 'removeEventListener', AnyFunction_2>>(target: T): BindEventFunction<T>;

Parameters

Parameter Type Description
target T 事件绑定的目标

Returns:

BindEventFunction<T>

返回事件绑定函数

Example

const bindWindowEvent = bindEvent(window)
const unbindClick = bindWindowEvent('click', console.log)
const unbindScroll = bindWindowEvent('scroll', console.log)