我在IE8中得到了以下错误:
消息:对象期望行: 27 Char: 1代码:0 URI:http://cdn.example.com/images/example4/js/libs/jquery.backgroundSize.js 消息:'$.fn‘为null或非对象行:8 Char: 1代码:0 URI:http://cdn.example.com/images/example4/js/libs/jquery.waitUntilExists.js 消息:'fn‘为空或非对象行: 62 Char: 73代码:0 URI:http://cdn.example.com/images/example4/js/libs/jquery.nicescroll.js 消息:对象期望行: 34 Char: 231代码:0 URI:http://cdn.example.com/images/example4/js/libs/backbone.js 消息:'Vent‘为null或非对象行: 19 Char: 3代码:0 URI:http://cdn.example.com/images/example4/js/models/auth.js
我们的站点是用Backbone.js和Require.js构建的用于依赖关系管理的SPA。这个问题只出现在IE8 (可能更早的版本)上。除了最后一个文件(因为'Vent‘扩展了Backbone.Event )之外,所有这些文件都是在我们的Require.js配置文件中作为Backbone.js的shims创建的。
Require.js配置:
requirejs.config({
baseUrl: 'http://cdn.staging.example.com/images/example4/js',
paths: {
underscore: './libs/underscore',
jquery: './libs/jquery',
backbone: './libs/backbone',
example: './libs/example',
blockui: './libs/jquery.blockUI',
backgroundsize: './libs/jquery.backgroundSize',
nicescroll: './libs/jquery.nicescroll',
waituntilexists: './libs/jquery.waitUntilExists',
swfobject: './libs/swfobject',
spinner: './libs/jquery.spinner'
},
//Create shims for Backbone
shim: {
'backgroundsize': {
deps: [ 'jquery'],
exports: 'backgroundsize'
},
'nicescroll': {
deps: ['jquery'],
exports: 'nicescroll'
},
'waituntilexists': {
deps: ['jquery'],
exports: 'waituntilexists'
},
'spinner': {
deps: ['jquery'],
exports: 'spinner'
},
'backbone': {
deps: [ 'underscore', 'jquery','blockui','backgroundsize','nicescroll', 'waituntilexists', 'swfobject', 'spinner'],
exports: 'Backbone'
}
}
});
requirejs(['app'],
function(App){
App.initialize();
});任何可能导致这种情况的建议,我们都使用Backbone.js 0.9.2和Require.js 2.0.6。
发布于 2013-02-15 08:46:01
IE对shims有一些问题,因为您可以在这里读到http://requirejs.org/docs/errors.html#nodefine
据我从http://requirejs.org/docs/api.html#config-shim了解
只使用其他"shim“模块作为shimmed脚本的依赖项,或者是在创建全局(如jQuery或have )之后没有依赖项并调用define()的AMD库。否则,如果您使用AMD模块作为shimmed模块的依赖项,则在生成之后,直到生成中的闪烁代码执行之后才可能对该AMD模块进行评估,并且会发生错误。最终的解决办法是升级所有闪烁的代码,使其具有可选的AMD ()调用。
当jquery依赖于shim或jquery没有加载时,可能会出现问题,因此它不能设置它是全局的。
发布于 2013-02-19 11:37:11
尝试将主干添加到您的主要需求中,如下所示:
requirejs(['app', 'backbone'], function(App){ App.initialize(); });另外,尝试使用r.js生成一个连接文件(确保关闭优化),您可以看到需要加载脚本的顺序。
https://stackoverflow.com/questions/14886553
复制相似问题