views:

80

answers:

2

Dear all, as MooTools 1.3 is out now, i´m going to update some scripts. BindWithEvent is now deprecated and has to be replaced, but how?

See this:

new Element('div', [.....]).addEvent('click',this.close.bindWithEvent(this,true));

I´m quite sure it has to be some sort of a function

new Element('div', [.....]).addEvent('click',function (event) { ????? } );

But how to bind with the upper close event?

+1  A: 

From the docs,

Function method: bindWithEvent

This function has been deprecated.

Example how you could replace this method:

myElement.addEvent('click', function(e){
    myFunction.bind(bind, [e]);
});
Anurag
fine, but:in my example this would result to:new Element().addEvent('click', function(e) { this.close.bind(bind,e);})and therefore, this.close would get a different meaning inside the new function than before.
tbh, from what I gather, `bindWithEvent` was an considered an edgecase. i don't see why you can't just replicate the code it used to use - i know several people that did. **in any case**, you can `bind` the anon function to the class instance and then pass the event object as suggested above to the method: http://www.jsfiddle.net/ExS4f/
Dimitar Christoff
A: 

sorry but for amateurs like me it's still hard to understand...

with mootools 1.2 my script used to run like this:

var listelements = $$('ul li');
    function myFunction(event, n){
     new Event(event).stop();
     alert(n);
    }
    for(var i=0; i < listelements.length; i++){
      var toggle = document.getElementById('toggleid');
      toggle.addEvent('click', myFunction.bindWithEvent(toggle, i));
    }

now in 1.3, after replacing the last row with:

toggle.addEvent('click', function(event, n){
                        myFunction.bind(toggle, i);
                        });

the script won't do nothing and, even without errors, the JS firebug console just stops at line 3603 of the mootools core:

defn = function(event)
sprutniks