KnowledgeHub
Questions
Tags
Users
Search
Alex Rivera
|
Logout
Edit Question
Title
Body
Reading the requireJs documentation, in order to fix the Circular Dependencies, is suggested to use exports to create an empty object for the module that is available immediately for reference by other modules. I try this code but it seems to do not work. What is wrong? P.S.: read the comments for seeing the output, especially the B module inside setTimeout call. // A module define([ 'b' ], function (b) { console.log('B:', b); // B, Object var A = { boo: 1 }; return A; }); // B module define([ 'a', 'exports' ], function (a, exports) { console.log('A:', a); // A, undefined (as I was expecting) exports.A = function () { return a; } var B = { bar: 1 }; setTimeout(function () { console.log('exports.A', exports.A()); // exports.A undefined // I would like to access the A object // which is defined in A module }, 500); return B; }); // main.js (function () { define([ 'a' ], function () { }); }());
Tags (comma-separated)
Save Edits
Cancel