如何触发所有模块都加载了requireJs

时间:2012-08-06 10:45:23

标签: javascript require

我使用requirejs加载javascript模块 有没有办法在加载所有模块时触发事件? 如果有,怎么样?

1 个答案:

答案 0 :(得分:3)

作为taken from the API,您可以向主requirejs函数添加回调:

requirejs(['jquery', 'canvas', 'app/sub'], callMe); // the second parameter is the callback

function callMe($, canvas, sub) {
  console.log('everything is loaded');
   // the libraries are now available as parameters in the same sequence as in the array
  console.log('loaded', $, canvas, sub);
}