首页 > 其他 > 详细

常见函数封装(自用,随时更新)

时间:2019-08-27 15:29:19      阅读:71      评论:0      收藏:0      [点我收藏+]

1.事件绑定与事件销毁

  /*
   *说明:为了绑定事件的时候,不支持传递scope.
   *参数:绑定目标,绑定事件,绑定函数,scrop常用this
   *返回:函数(用于销毁绑定)
   */
function connectEvent(target, event_name, fn, scope) { if (!target.on || typeof target.on != ‘function‘) return; if (!fn || !event_name) return; const $fn = (e) => { fn.call(scope || null, e); } target.on(event_name, $fn); return $fn; } /* *说明:为了避免解绑定事件的时候,fn传递空导致解绑所有类型的事件封装 *参数:绑定目标,绑定事件,销毁上述函数 */

function disconnectEvent(target, event_name, fn) { if (!target.un || typeof target.un != ‘function‘) return; if (!fn || !event_name) return; target.un(event_name, fn); }

 

常见函数封装(自用,随时更新)

原文:https://www.cnblogs.com/lucio110/p/11418355.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!