On Mar 24, 1:25 am, Mark McDonnell <[email protected]> wrote: > that makes sense thanks :) > > But I'm building my own js library that abstracts the api between browsers > and obviously there is the chance that a user with will specify an anonymous > function as the handler. How does a library like jQuery's bind() method > handle these situations ?
As Poetro said, the usual approach is to add a function that calls the listener. If you assign an anonymous function, you can't specifically remove that listener but you can remove all listeners for an event type. So if you have a function that you want to add as a listener and might want to remove later, give it a name and add it as a reference, not a an anonymous fuction. There is an interesting discussion in clj: "Any need for addEventListener() and attachEvent() at all?" <URL: http://groups.google.com/group/comp.lang.javascript/browse_frm/thread/33e4472d2fe16e53/6e1e6e320af46f46?lnk=gst&q=any+need+for+addEventListener#6e1e6e320af46f46 > -- Rob -- To view archived discussions from the original JSMentors Mailman list: http://www.mail-archive.com/[email protected]/ To search via a non-Google archive, visit here: http://www.mail-archive.com/[email protected]/ To unsubscribe from this group, send email to [email protected]
