seajs中,两个js文件暴露的方法相互调用,出现bug

a.js文件
define(function(require, exports) {

  var b = require("b.js");
  exports.write = function(msg){
      return "我写:" + msg;
  };
  console.log("--------------------");
  console.log(b.say("我在a.js"));
  console.log("--------------------");

});

b.js
define(function(require, exports) {

  var a = require("a.js");
  exports.say = function(msg){
      return "我说:" + msg;
  };
  console.log("--------------------");
  console.log(a.say("我在b.js"));
  console.log("--------------------");

});

a.html
<script>

seajs.use("a.js");

</script>

b.html
<script>

seajs.use("b.js");

</script>

--------------------------------上位源代码------------------------------
原因自己觉得是,运行a.html文件,首先加载a.js文件,之后由于var b = require("b.js"),将会引用b.js,那么b.js文件就会运行起来,当b.js文件运行到console.log(a.say("我在b.js")),那么就会报错,求解决.

阅读 4.2k
撰写回答
你尚未登录,登录后可以
  • 和开发者交流问题的细节
  • 关注并接收问题和回答的更新提醒
  • 参与内容的编辑和改进,让解决方法与时俱进
推荐问题