JavaScript:事件-VERSUS-回调

时间:2014-06-06 14:52:04

标签: javascript jquery performance javascript-events callback

JavaScript更合理/更快:使用callbacks()或对events作出反应?

JavaScript:回调

doSomething(function(){
   //one or more callbacks (onSuccess, onError, etc)
});

JavaScript:活动

function initSomething(){
   //do something
   $(document).trigger('reactOnEvent');    
}

$(document).on('reactOnEvent', function(){
   //callback via event
});
initSomething();

0 个答案:

没有答案