The handler function itself should be used at addEventListener() and removeEventListener()
- BAD_EVENT_LISTENER_CALL
- Error
- Medium
- No tags
This rule applies when the handler is mistakenly called at the argument of addEventListener() and removeEventListener().
The second argument of addEventListener() and removeEventListener() should be the handler function itself, not its return value. When a non-function value is used as a handler, a TypeError exception may occur depending on the type of the value.
This rule also applies to the analogous setTimeout(), setInterval(), setImmediate() and process.nextTick().
Noncompliant Code Example
View with compliant examples side by sidefunction clickHandler() {
handleClick();
}
window.addEventListener('click', clickHandler()); // BAD_EVENT_LISTENER_CALL alarmCompliant Code Example
View with noncompliant examples side by sidefunction clickHandler() {
handleClick();
}
window.addEventListener('click', clickHandler);Version
This rule was introduced in DeepScan 1.31.0.