我在结束 body 标记之前调用 Require.js:
<script data-main="assets/scripts/src/main.js" src="assets/scripts/lib/requirejs/require.js"></script>
</body>
这是我的main.js
内容:
requirejs.config({
urlArgs: "bust=" + (new Date()).getTime(), // override browser cache
});
require(['views/appView'], function (App) {
App.initialize(); // this is just to test the module is actually loading
});
appView.js 包含:
define([
'modernizr',
'jquery',
'underscore',
'backbone',
'common', // this module has about 4 other dependencies too
'dust',
'routers/main',
'views/main'
], function (Modernizr, $, _, Backbone, Common, dust, router, mainView) {
// This is supposed to load, even if jQuery loads after the DOM ready event
$(document).on('ready', function () {
console.log("I don't want to play nice");
});
return {
initialize: function () {
console.log("Init");
}
}
});
不幸的是,这:根本console.log("I don't want to play nice");
不会发生。
这就是我的网络时间线在 Chrome 开发工具中的样子。如您所见,DOM 就绪事件在 jQuery 加载之前触发 - 但 AFAIK,jQuery 知道如何处理这个!所以我迷路了。