refering to JavaScript window resize event
they mentioned they solution was to add a listener to the window with the "resize" event and said overriding window.resize is bad practise...
my question is why?
refering to JavaScript window resize event
they mentioned they solution was to add a listener to the window with the "resize" event and said overriding window.resize is bad practise...
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.