gpt4 book ai didi

javascript - 使用 Backbone.js w/Require.js 的站点在 IE8 中的错误

转载 作者:行者123 更新时间:2023-11-30 06:35:24 25 4
gpt4 key购买 nike

我在 IE8 中返回以下错误:

Message: Object expected Line: 27 Char: 1 Code: 0 URI: http://cdn.example.com/images/example4/js/libs/jquery.backgroundSize.js

Message: '$.fn' is null or not an object Line: 8 Char: 1 Code: 0 URI: http://cdn.example.com/images/example4/js/libs/jquery.waitUntilExists.js

Message: 'fn' is null or not an object Line: 62 Char: 73 Code: 0 URI: http://cdn.example.com/images/example4/js/libs/jquery.nicescroll.js

Message: Object expected Line: 34 Char: 231 Code: 0 URI: http://cdn.example.com/images/example4/js/libs/backbone.js

Message: 'Vent' is null or not an object Line: 19 Char: 3 Code: 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 的垫片。

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。

最佳答案

IE 存在一些垫片问题,您可以在此处阅读 http://requirejs.org/docs/errors.html#nodefine

据我了解 http://requirejs.org/docs/api.html#config-shim

Only use other "shim" modules as dependencies for shimmed scripts, or AMD libraries that have no dependencies and call define() after they also create a global (like jQuery or lodash). Otherwise, if you use an AMD module as a dependency for a shim config module, after a build, that AMD module may not be evaluated until after the shimmed code in the build executes, and an error will occur. The ultimate fix is to upgrade all the shimmed code to have optional AMD define() calls.

将 jquery 作为 shim 的依赖项可能存在问题,或者 jquery 未加载,因此无法将其设置为全局。

关于javascript - 使用 Backbone.js w/Require.js 的站点在 IE8 中的错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14886553/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com