requirejs模块未定义

我有以下目录结构

scripts modules tabs.js app.js 

我在app.js中有以下代码

 define([ 'jquery', 'underscore', 'modules/tabs', ], function($, _, Tabs) { var App = (function() { var init = function() { console.log('app'); Tabs.init(); }; return { init: init }; }()); return App; }); 

跟随tabs.js中的代码

 define([ 'jquery', 'underscore', '../app' ], function($, _, App) { var Tabs = (function() { var init = function() { console.log('tabs init'); App.init(); }; return { init: init } }()); return Tabs; }); 

可以看出,依赖于tabs.js和tabs.js的app.js都依赖于app.js当我在app.js中调用Tabs.init()时会发生什么,然后它可以正常工作但是当我做App时。 tabs.js中的init()然后App未定义。 我怎样才能使这个工作,以便当我在tabs.js中执行App.init()时它应该工作?

如果定义循环依赖(“a”需要“b”而“b”需要“a”),那么在这种情况下,当调用“b”的模块函数时,它将获得“a”的未定义值。 “b”可以在使用require()方法定义模块后稍后获取“a”(确保将require指定为依赖项,以便使用正确的上下文查找“a”):

 //Inside b.js: define(["require", "a"], function(require, a) { //"a" in this case will be null if "a" also asked for "b", //a circular dependency. return function(title) { return require("a").doSomething(); } } ); 

http://requirejs.org/docs/api.html#circular