简体   繁体   English

Require.js:未捕获的TypeError:对象函数…没有方法

[英]Require.js : Uncaught TypeError: Object function … has no method

I'm getting an Uncaught TypeError when i refresh the page, my js/app/main.js file can't call the method update() on js/app/utilities/resize.js . 刷新页面时出现Uncaught TypeError,我的js / app / main.js文件无法在js / app / utilities / resize.js上调用方法update()。

Error output 错误输出

Uncaught TypeError: Object function U(n){return n&&typeof n=="object"&&!me(n)&&ne.call(n," wrapped ")?W(n)} has no method 'update' 未捕获的TypeError:对象函数U(n){返回n && typeof n ==“ object” &&!me(n)&& ne.call(n,“ 包装的 ”)?W(n)}没有方法'update'

I haven't managed to isolate/replicate the issue into a simplified working example unfortunately. 不幸的是,我没有设法将问题隔离/复制为一个简化的工作示例。 But you can click on the js files within the folder tree below for gists. 但是您可以在下面的文件夹树中单击js文件,以获得要点。

  • index.html 的index.html
  • js / js /
    • app.js app.js
    • lib / lib /
      • require.js require.js
      • jquery.js 的jquery.js
      • ... etc ...等等
    • app / 应用程式/
      • main.js - Uncaught TypeError @line 566 main.js- 未捕获的TypeError @line 566
      • utilities / 公用事业/

app.js app.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(){});

The method update() is being called on resize.js from main.js ; main.jsresize.js上调用了update()方法;

main.js main.js

define([ 'require' , 'jquery' , ... ,'resize' ], function( require , $ , ... , resize ) { define(['require','jquery',...,'resize'],function(require,$,...,resize){

... ...

function setup() { 函数setup(){

  resize.update(); // Uncaught TypeError happens here 

} }

$doc.ready( setup ); $ doc.ready(setup);

resize.js resize.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 ); }
    }
});

Thanks in advance 提前致谢


Edit : It seems it was a dependancy issue. 编辑 :似乎这是一个依赖问题。 Adding "resize" to require on app.js has resolved it; 在app.js上添加要求的“调整大小”已解决该问题;

require(["resize","app/main"],function(){});

I thought suppling "resize" to define() in main.js would have ensured correct deps; 我认为在main.js中提供“ resize”到define()可以确保正确的deps。

define([ 'require' , 'jquery' , ... ,'resize' ], function( require , $ , ... , resize )...

It seems it was a dependancy issue. 看来这是一个依赖问题。

Adding "resize" to require() within app.js has resolved it; 在app.js中的require()中添加“ resize”可以解决该问题;

require(["resize","app/main"],function(){});

I thought suppling "resize" to define() in main.js would have ensured correct deps; 我认为在main.js中提供“ resize”到define()可以确保正确的deps。

define([ 'require' , 'jquery' , ... ,'resize' ], function( require , $ , ... , resize )...

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 Backbone.js和Require.js-未捕获的TypeError:对象函数(){return parent.apply(this,arguments); }没有方法“开” - Backbone.js and Require.js - Uncaught TypeError: Object function (){ return parent.apply(this, arguments); } has no method 'on' require.js未捕获的TypeError:对象的属性&#39;$&#39; <Object> 不是一个功能 - require.js Uncaught TypeError: Property '$' of object #<Object> is not a function Require.js未被捕获的TypeError:jqOAuth不是一个函数 - Require.js Uncaught TypeError: jqOAuth is not a function Require.js Uncaught TypeError:undefined不是函数 - Require.js Uncaught TypeError: undefined is not a function 未捕获的TypeError:使用require.js时undefined不是函数 - Uncaught TypeError: undefined is not a function when using require.js 未捕获的TypeError:对象(JS函数)没有方法“应用” - Uncaught TypeError: Object (JS Function) has no method 'apply' require.js和bone.js获取未捕获的TypeError - require.js and backbone.js getting Uncaught TypeError 未捕获的TypeError:对象函数()没有方法项 - Uncaught TypeError: Object function () has no method items 未捕获的TypeError:对象函数()没有方法“替换” - Uncaught TypeError: Object function () has no method 'replace' 未捕获的TypeError:对象函数没有方法 - Uncaught TypeError: Object function has no method
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM