Tuesday, April 08, 2008

Event.on is making my spider sense tingle

I've been using the YUI libraries at work on a new project and I'm vaguely dissatisfied with the way event listeners are attached using YAHOO.util.Event. I think I have a different way that could be better, although I haven't tried it myself.

Instead of passing the function, the arguments and the scope separately, it might make more sense to pass an inline function that wraps the function call and makes sure that the scope and arguments are correct.

Instead of:
Event.on("elementId", function, arg, scope)
You would have:
Event.on("elementId", function() { scope.function(arg) });
At the very least, the latter seems more flexible to me. Maybe I've been reading too much Jon Resig.

0 Comments:

Post a Comment

Previous Posts

Powered by Blogger