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

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")),那么就会报错,求解决.


循环依赖

【热门文章】
【热门文章】