How to merge if/else statements in JS?

Posted by babs on Stack Overflow See other posts from Stack Overflow or by babs
Published on 2010-04-18T12:34:33Z Indexed on 2010/04/18 12:43 UTC
Read the original article Hit count: 379

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);
}

© Stack Overflow or respective owner

Related posts about merge

Related posts about if-else-statement