function addLoadEvent(func){ var oldonLoad = window.onload; if(typeof window.onload != 'function'){ window.onload = func; }else{ window.onload = function(){ oldonLoad(); func(); } } } function c1(){ console.log(1) } function c2(){ console.log(2) } function c3(){ console.log(3) } addLoadEvent(c3) addLoadEvent(c1) addLoadEvent(c2)