Attaching a click handler in a cross-browser way I have been attempting to have a method call, with a parameter, inside of a ternary operator to simplify some code.

Code:

 if (window.addEventListener) {
     btnArray[index].addEventListener('click', function() {
        doMassClick( btnArray[index], nameArray[index]);
     });
 } else {
     btnArray[index].attachEvent('onclick', function() {
        doMassClick( btnArray[index], nameArray[index]);
     });
 }


I was able to simplify this down to:

btnArray[index][ window.addEventListener ? 'addEventListener' : 'attachEvent'](window.addEventListener ? 'click' : 'onclick', function() {
    doMassClick( btnArray[index], nameArray[index]);
});


I'd love to know how this can be simplified/cleaned up more..
The common thing in your code is the listener.

function massClickListener() {
    doMassClick( btnArray[index], nameArray[index]);
}


Then it is easier to use the ternary:

btnArray[index][ window.addEventListener ? 'addEventListener' : 'attachEvent'](window.addEventListener ? 'click' : 'onclick', massClickListener);


Personally however, I think this is better:

if (window.addEventListener) {
    btnArray[index].addEventListener('click', massClickListener);
} else {
    btnArray[index].attachEvent('onclick', massClickListener);
}


Using the conditional operator to choose different methods is not very readable.

Another option might be to use a framework that does these kinds of things for you.