刷新页面时出现 Uncaught TypeError,我的js/app/main.js文件无法调用js/app/utilities/resize.js上的方法 update() 。
错误输出
未捕获的类型错误:对象函数 U(n){return n&&typeof n=="object"&&!me(n)&&ne.call(n," Wrapped ")?W(n)} 没有方法“更新”
不幸的是,我没有设法将问题隔离/复制到简化的工作示例中。但是您可以单击下面文件夹树中的 js 文件以获取要点。
- 索引.html
- js /
应用程序.js
require.config({
urlArgs: "bust=" + (new Date()).getTime(),
baseUrl: WP.THEME_URL+"/js",
paths: {
app : "app"
, jquery : "lib/jquery-2.0.2.min"
, ...
, resize : "app/utilities/resize"
, ...
}
});
require(["app/main"],function(){});
正在从main.js在resize.js上调用update()方法;
main.js
定义([ 'require' , 'jquery' , ... ,'resize' ], function( require , $ , ... , resize ) {
...
功能设置(){
resize.update(); // Uncaught TypeError happens here
}
$doc.ready(设置);
调整大小.js
define([],function () {
var resizeItems = [],
update = function () {
for (i = 0; i < resizeItems.length; i++){
var item = resizeItems[i];
item.callback( App.screen.width , App.screen.height );
}
};
return {
update : update,
add : function( item ) { resizeItems.push( item ); }
}
});
提前致谢
编辑:这似乎是一个依赖问题。在 app.js 上将“resize”添加到要求已解决;
require(["resize","app/main"],function(){});
我认为在 main.js 中为 define() 提供“resize”可以确保正确的 deps;
define([ 'require' , 'jquery' , ... ,'resize' ], function( require , $ , ... , resize )...