I
Integralist
Hi,
As the subject suggests I'm trying to work out a way I can get this (very basic) library I'm working on to be able standardise the event object for users so they dont have to.
I've set-up a jsFiddle here: http://jsfiddle.net/3QVhY/
If you click on either the red/blue border and check your console you'll see some logged information, and the if you click on the 'remove listener' button and do the same again then nothing extra will happen - which is fine, that's exactly what it's supposed to do.
The problem I have is that if I want to standardise the event object, the only way I know how is to wrap the users specified handler function in an anonymous function within the addEventListener call (which passes through theevent object) and I then call the users handler but pass through the standardised version of the event.
But this breaks the removeEventListener because anonymous functions aren't seen as the same.
So me doing this...
eventType = eventType.toLowerCase();
element.addEventListener(eventType, function(e) {
handler(__mylib.events.standardize(e));
}, false);
....doesn't work.
Does anyone know how the majority of JavaScript libraries achieve this typeof feature whereby the event object is standardised?
Also, I have checked a couple of the popular js libraries and found that none of them were able to provide an api to work around when/if a user uses an anonymous function while setting up an event listener. But these libraries were capable of returning to the handler function a standardised event object.
It maybe that I have to set-up my library differently to achieve this type of functionality, although I'm not sure how I'd go about doing this so I'd need advice on this as well.
Regards,
Mark
As the subject suggests I'm trying to work out a way I can get this (very basic) library I'm working on to be able standardise the event object for users so they dont have to.
I've set-up a jsFiddle here: http://jsfiddle.net/3QVhY/
If you click on either the red/blue border and check your console you'll see some logged information, and the if you click on the 'remove listener' button and do the same again then nothing extra will happen - which is fine, that's exactly what it's supposed to do.
The problem I have is that if I want to standardise the event object, the only way I know how is to wrap the users specified handler function in an anonymous function within the addEventListener call (which passes through theevent object) and I then call the users handler but pass through the standardised version of the event.
But this breaks the removeEventListener because anonymous functions aren't seen as the same.
So me doing this...
eventType = eventType.toLowerCase();
element.addEventListener(eventType, function(e) {
handler(__mylib.events.standardize(e));
}, false);
....doesn't work.
Does anyone know how the majority of JavaScript libraries achieve this typeof feature whereby the event object is standardised?
Also, I have checked a couple of the popular js libraries and found that none of them were able to provide an api to work around when/if a user uses an anonymous function while setting up an event listener. But these libraries were capable of returning to the handler function a standardised event object.
It maybe that I have to set-up my library differently to achieve this type of functionality, although I'm not sure how I'd go about doing this so I'd need advice on this as well.
Regards,
Mark