I've been playing with the Event.observe function as i need it to pass
extra arguments to my callback function and keeping 'this' in the
scope of the callback function Object.
I don't know if theres a better way to do this but thought i would
share it here.

observe: function(){
        var args = $A(arguments), el = $(args.shift()), evt = args.shift(),
func = args.shift();
        if(!func) return;
        if(el.addEventListener){
                el.addEventListener(evt, func.bind.apply(func, 
[func].concat(args)),
false);
        }else if(el.attachEvent){
                el.attachEvent('on'+evt, func.bind.apply(func,
[func].concat(args)) );
        }
}

I can now do this :

Event.observe('myElement', 'click', callBackFunc, extraArg1,
extraArg2.....);

callBackFunc now recieves Arguments[0] => MouseEvent, [1] =>extraArg1,
[2] =>extraArg2
and 'this' is a reference to callBackFunc and therefore any of its
properties etc.

It still allows you to set the Scope of 'this' :
Event.observe('myElement', 'click', callBackFunc.bind('anyObj'),
extraArg1, extraArg2....);
or
Event.observe('myElement', 'click', callBackFunc.bind('anyObj',
extraArg1, extraArg2....) );

Any thoughts??
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"Prototype: Core" group.
To post to this group, send email to prototype-core@googlegroups.com
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/prototype-core?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to