[英]replace bindwithevent function in mootools 1.3 (upgrade from 1.2)
[英]how to replace bindwithevent in mootools 1.3
我想知道如何替換Mootools 1.3中的bindWithEvent函數,文檔中的示例非常基本:
Element.addEvent('click', function(e){
myFunction.bind(bind, [e]);});
但是,如果我需要將參數傳遞給事件處理程序怎么辦? 這是Mootools 1.2中的方法:
Element.addEvent('click', function(e, param) { e.stop(); alert(param) }.bindWithEvent(this,['text']);
關於如何在Mootools 1.3中替換它的任何想法。
更新:我發現一個非常丑陋的解決方案,但至少在我找到一個內置解決方案時它可以工作:
Element.addEvent('click', function(e){ e.stop(); this.bind.myFunc(this.param);}.bind({bind:this, param: 'text'}));
el.addEvent('click', function(event){
myFunction(event, param1, param2); // can use .pass and bind this again
}.bind(this));
很難解釋為什么它被棄用了。
類上下文中的示例:
var foo = new Class({
initialize: function(el) {
document.id(el).addEvent('click', function(event){
this.foo(event, "hello");
}.bind(this));
},
foo: function(event, what) {
console.log(event, this); // this is the class instance
alert(what);
}
});
new foo("foo");
您應該閱讀從1.2升級到1.3的頁面: http : //github.com/mootools/mootools-core/wiki/Update-from-1.2-to-1.3
這是我想出的: http : //jsfiddle.net/MBx2D/2/
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.