Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

RequireJS: Can two modules require each other?

Is the following possible with RequireJS?

Module 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
});

Module 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
});
like image 689
wilsonpage Avatar asked Oct 25 '11 16:10

wilsonpage


1 Answers

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

The short answer - you can, but should not.

like image 59
Infeligo Avatar answered Sep 25 '22 05:09

Infeligo