【问题标题】:RequireJS: Can two modules require each other?RequireJS:两个模块可以互相要求吗?
【发布时间】:2011-12-15 02:46:54
【问题描述】:

RequireJS 是否可以实现以下操作?

模块 A:

define([
  'moduleB'
], function(moduleB){

  // log moduleB exports
  console.log(moduleB);


  // exports
  var moduleA = {};


  // set a var to export
  moduleA.varA = 'This is a variable in module A';


  // return exports   
  return moduleA
});

模块 B:

define([
  'moduleA'
], function(moduleA){

  // log moduleA exports
  console.log(moduleA);

  // exports
  var moduleB= {};


  // set a var to export
  moduleB.varB= 'This is a variable in module B';



  // return exports
  return moduleB
});

【问题讨论】:

    标签: javascript architecture module requirejs


    【解决方案1】:

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

    简短的回答 - 你可以,但不应该。

    【讨论】:

      猜你喜欢
      • 2014-06-14
      • 1970-01-01
      • 2015-06-16
      • 2019-10-21
      • 1970-01-01
      • 1970-01-01
      • 2022-06-29
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多