I want to attach a lot of properties to a single object. I do not want to do this in one single file. Is the example below a correct and good way to break this into multiple files?
For example, in main.js
,
var obj = {};
obj = require('./utils');
obj = require('./part1');
// other requires omitted...
obj.init = function() {
obj.util1();
obj.helper1();
};
module.exports = obj;
in utils.js
,
var obj = require('./main');
obj.util = function() {
console.log('util1');
};
// other methods omitted...
module.exports = obj;
in part1.js
,
var obj = require('./main');
obj.helper1= function() {
obj.util1();
console.log('helper1');
};
// other methods omitted...
module.exports = obj;
and there are part2.js
, part3.js
, etc.
You see there is circular dependency in the files. Is there a better way than the example above?