简体   繁体   中英

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 .

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'

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.

  • index.html
  • js /
    • app.js
    • lib /
      • require.js
      • jquery.js
      • ... etc
    • app /
      • main.js - Uncaught TypeError @line 566
      • utilities /

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.js

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

...

function setup() {

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

}

$doc.ready( setup );

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;

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

I thought suppling "resize" to define() in main.js would have ensured correct 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;

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

I thought suppling "resize" to define() in main.js would have ensured correct deps;

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM