zoukankan      html  css  js  c++  java
  • JS_eventBind

    /*
    * Function.prototype.bind 外置函数;
    * 当连续bind事件的时候无法保证顺序;
    */
    if
    (!Function.prototype.bind){ Function.prototype.bind = function(){ var args = Array.prototype.slice.call(arguments); var _obj = args.shift(); var _fun = this; return function(){ return _fun.apply(_obj,args.concat(Array.prototype.slice.call(arguments))); }; }; } var eventHandler = { add:function(node,en,fu){ node.addEventListener ? node.addEventListener(en,fu,false) : node.attachEvent("on" + en, fu); }, remove:function(node,en,fu){ node.removeEventListener ? node.removeEventListener(en,fu,false) : node.detachEvent("on" + en, fu); }, guid:0, bind:function(node,en,fu){ var _this = this; fu = fu.bind(node); _this.guid++; if(!node.evenfun) node.evenfun = {}; if(!node.evenfun[en])node.evenfun[en] = {}; node.evenfun[en][_this.guid] = fu; _this.add(node,en,node.evenfun[en][_this.guid]); }, unbind:function(node,en){ var _this = this; if(!node.evenfun || !node.evenfun.hasOwnProperty(en)) return; for(var i in node.evenfun[en]){ _this.remove(node,en,node.evenfun[en][i]); } delete node.evenfun[en]; }, bindBn:function(node,en,fu){ var funame = fu.toString(),_this = this; fu = fu.bind(node); if(!node.evenfun) node.evenfun = {}; if(!node.evenfun[en])node.evenfun[en] = {}; node.evenfun[en][funame] = fu; _this.add(node,en,node.evenfun[en][funame]); }, unbindBn:function(node,en,name){ var _this = this; name = name.toString(); if(!node.evenfun || !node.evenfun[en].hasOwnProperty(name)) return; _this.remove(node,en,node.evenfun[en][name]); delete node.evenfun[en][name]; } }
  • 相关阅读:
    【搜索】棋盘 luogu-3956
    【动态规划】石子合并 luogu-1880
    【动态规划】合唱队形 luogu-
    【模拟】报名签到 luogu-4445
    【排序+贪心】导弹拦截 luogu-1158
    【模拟】不高兴的津津
    【模拟】选数 luogu-1037
    「JOISC2020」建筑装饰 4
    「清华集训」小 Y 和恐怖的奴隶主
    「CF708E」Student's Camp
  • 原文地址:https://www.cnblogs.com/somesayss/p/2787918.html
Copyright © 2011-2022 走看看