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
_.debounce() loses event.currentTarget #1905
Comments
If the property is changed on the event object reference that's outside the scope of Underscore. If you use a lib like jQuery that may help as they make a synthetic event object which you should be able to reference without issue. |
I don't think you're going to get around this. Passing a second parameter can get around this. fiddle var debounced = _.debounce(fn, 50);
document.querySelector('.debounced-input').addEventListener('keyup', function(event) {
debounced(event, event.currentTarget);
}); |
Yep, this is outside of the scope of underscore. Consider a DOM event micro framework like |
Here's an example of it working with jQuery. |
I can still get the element that |
@jridgewell any idea how to get around this in a React onChange. when i don't use debounce I am able to access the proper event in my onChange function but when I use
|
See my second suggestion. |
This is a matter of implementation. You need to persist the event. onChange should call a persist and THEN pass the persisted event to the debounced handler:
|
I am unable to get the
event.currentTarget
when usingaddEventListener
with_.debounce()
.Here’s a fiddle.
The text was updated successfully, but these errors were encountered: