I\'m having the following 3 files.
user.js requires room.js and room.js requires user.js.
user.js
var Room = require(\'./room.js\');
var Use
The difference between:
/* code above */
function a() {};
and
/* code above */
var a = function () {};
Is that in the first example a will be function already in the code above, but not in the second example.
Once you understand that you can come to this simple solution:
// user.js
module.exports = User;
function User() {};
User.prototype.test = function () {
var Room = require('./room');
return new Room();
};
// room.js
module.exports = Room;
function Room() {};
Room.prototype.test = function () {
var User = require('./user');
return new User();
};
// index.js
var User = require('./user.js');
var Room = require('./room.js');
var user = new User(Room);
var room = new Room(User);