三項演算子によるクロスブラウザのaddEventListener

by ethertank

JavaScript

function addEvent(e,n,o,u)(e.addEventListener)?e.addEventListener(n,o,u):(e.attachEvent)?e.attachEvent('on'+n,o):"";

//実行(対象、イベント、処理, useCapture)
addEvent(window, "load", init, false);

//テスト用関数
function init() { alert("eventListenerOK"); }