I have an issue with browserified JS where defined functions are returning undefined. I have a feeling it's because two of my files require each other. The files themselves are too big to put in this question so I'll simplify it here:
file_A.js
var fileB = require('./file_B.js');
var fileA = {};
module.exports = fileA;
fileA.functionOne = function() {
// do something
fileb.functionOne();
}
fileA.functionTwo = function() {
// do something else
}
file_B.js
var fileA = require('./file_A.js');
var fileB = {};
module.exports = fileB;
fileB.functionOne = function() {
// do something
fileA.functionTwo();
}
File A can call the functions in File B no problem. But when I try to call the File A functions from File B, I just get undefined
.
As I said, I have a feeling it's because they're requiring each other. But they do need to require each other. I haven't found anywhere in the docs that tells you not to do this, or how to avoid doing it if you have to.
Please help :(