Refering to JavaScript window resize event
They mentioned the solution was to add a listener to the window with the resizeevent and said overriding
window.resize` is bad practice.
My question is why?
Refering to JavaScript window resize event
They mentioned the solution was to add a listener to the window with the resizeevent and said overriding
window.resize` is bad practice.
My question is why?
The same applies to all events: using .onsomething = function() {...}
is an assignment, and will overwrite any existing event handler, which can bugger up other pieces of code.
addEventListener
, on the other hand, will add a new event handler without affecting existing ones.
One thing to watch out for is that I've seen numerous cases where the same event handler gets repeatedly added due to bad code, whereas using .onsomething = ...
would avoid the problem.