标签:匿名 assert err doc deb click cli ror logs
<button id="test">点我</button> <script> var button={ clicked:false, click:function(){ debugger; this.clicked=true; console.assert(!(button.clicked),"The button has been clicked"); } } var elem=document.getElementById("test");
//error
//elem.addEventListener("click",button.click,false); elem.addEventListener("click",bind(button,"click"),false); function bind(context,name){ return function(){ return context[name].apply(context,arguments); }; }
用用匿名函数和闭包加apply强制待定函数调用时使用特定上下文
标签:匿名 assert err doc deb click cli ror logs
原文地址:http://www.cnblogs.com/gaocong/p/6626355.html