var EventUtil = { addHandler:function(element,type,handler){ if(element.addEventListener){ element.addEventListener(type,handler,false); }else if(element.attachEvent){ element.attachEvent("on"+type,handler); }else{ element["on"+type] = handler; } }, removeHandler:function(element,type,handler){ if(element.removeEventListener){ element.removeEventListener(type,handler,false); }else if(element.detachEvent){ element.detachEvent("on"+type,handler); }else{ element["on"+type] = null; } }};var handler={ message:"Event handled", handleClick:function(event){ alert(this.message); }};var btn=document.getElementById("btn");EventUtil.adddHandler(btn,"click",bind(handler.handleClick,handler));
1 回答
慕斯王
TA贡献1864条经验 获得超2个赞
bind()函数有定义....在603页
function bind(fn, context){ return function(){ return fn.apply(context, arguments); }; }
看书要认真 = =
添加回答
举报
0/150
提交
取消