how to replace bindwithevent in mootools 1.3

后端 未结 2 1409
悲&欢浪女
悲&欢浪女 2021-01-21 22:11

I wonder how to replace the bindWithEvent function in Mootools 1.3, the example in the documentation is very basic:

Element.addEvent(\'click\', function(e){
myFu         


        
相关标签:
2条回答
  • 2021-01-21 22:41

    You should read the upgrade from 1.2 to 1.3 page: http://github.com/mootools/mootools-core/wiki/Update-from-1.2-to-1.3

    This is what I came up with: http://jsfiddle.net/MBx2D/2/

    0 讨论(0)
  • 2021-01-21 22:47
    el.addEvent('click', function(event){
        myFunction(event, param1, param2); // can use .pass and bind this again
    }.bind(this));
    

    it's hard to explain why it got deprecated though.

    example in a class context:

    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");
    
    0 讨论(0)
提交回复
热议问题