Add Event.addMethods to allow adding methods to Event instances
Reported by Ken Snyder | July 3rd, 2008 @ 04:23 AM
I've created a patch that will allow developers to roll out their own Event instance methods.
Examples of such methods:
getKeyCode - gets event.keyCode or event.charCode, whichever is set
getAscii - gets the ASCII code of the key pressed (if any)
getWheelDetail - gets event.detail or event.wheelDelta, whichever is set
Comments and changes to this ticket
-
Juriy Zaytsev July 3rd, 2008 @ 01:54 PM
I think it might make sense to use an event decorator/wrapper rather than extending event object with methods. Events have read-only properties, extending them might introduce name-clashes. Wrappers could solve these problems.
-
Ken Snyder July 3rd, 2008 @ 02:34 PM
Hmm. Maybe I'm taking the wrong approach then. I see that Prototype adds methods to all event instances such as stop, inspect, isRightClick. As a developer, I would like to add additional methods.
-
Juriy Zaytsev July 3rd, 2008 @ 02:38 PM
Ken, I understand exactly what you mean. As a matter of fact I'm using almost identical patch for quite some time : ) (with custom methods like Event#isPointerWithin)
I'm just thinking out loud about a future of our Event implementation. Do you think wrappers would make sense?
-
John-David Dalton July 7th, 2008 @ 01:54 PM
- → State changed from new to enhancement
+1 For wrappers. It's the only way to avoid Host Object/Native Object conflicts/bugs. For example Opera's implementation of event.timestamp returns 0. If you try to change that it causes an error. With wrappers we could avoid things like that. Also with Element methods if we used a wrapper we wouldn't have to worry about form elements and the "select" method and othersAlso I dig late binding mixins :)
Please Login or create a free account to add a new comment.
You can update this ticket by sending an email to from your email client. (help)
Create your profile
Help contribute to this project by taking a few moments to create your personal profile. Create your profile »
The Prototype JavaScript library.
