-
Notifications
You must be signed in to change notification settings - Fork 58
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Overriding of existing listeners #28
Comments
Thanks for picking that up. Do you have any suggestion on how to attach to an existing event? |
@shawnmclean Hi. Thanks for fast reaction. I think it's possible to do something like: function proxyMethod(object, propName, method) {
const existingMethod = object[propName];
let finalMethod = method;
if (typeof existingMethod === 'function') {
finalMethod = (...args) => {
existingMethod(...args);
return method(...args)
};
}
object[propName] = finalMethod;
}
window.onclick = () => console.log('attached earier');
proxyMethod(window, 'onclick', () => console.log('click'));
proxyMethod(window, 'onclick', () => console.log('click #2')); |
Using the moment, I would like to ask did you thought about https://developer.mozilla.org/en-US/Add-ons/WebExtensions/API/idle support? |
Thanks for the code suggestion. Hey! If they now have an idle feature in the browser's api, why use this one? (I haven't dug deeper into it to see what constitutes an |
They have it. But only recent browsers support it. And edge, for example, doesn't. So, it's nice to have some |
I think, it will be better to check if the
window
object already have a value inonclick
,onmousemove
etc. to not override them:https://github.com/shawnmclean/Idle.js/blob/master/src/idle.coffee#L52
The text was updated successfully, but these errors were encountered: