Hello! I'm wondering how to merge these JS if/else statements correctly?
if (window.addEventListener) { window.addEventListener('dosomething', foo, false); }
else { document.addEventListener('dosomething', foo, false); }
if (window.attachEvent) { window.attachEvent('dosomething', foo); }
else { document.attachEvent('dosomething', foo); }
EDIT I
The original code was:
if (window.attachEvent) { window.attachEvent('dosomething', foo); }
else if (window.addEventListener) { window.addEventListener('dosomething', foo, false); }
else { document.addEventListener('dosomething', foo, false); }
Now, I'd like to add
document.attachEvent('dosomething', foo);
here.
EDIT II
Turns out, "document.addEventListener" / "document.attachEvent" are redundant, so I'll leave it to
if (window.addEventListener) { window.addEventListener('dosomething', foo, false); }
else if (window.attachEvent) { window.attachEvent('dosomething', foo); }
Thanks everyone!