I made a game engine that I can use on the server side as well, and I planed to run it with Node.js.
The engine is in its entirety packed into one file, and at the end, I export it like this:
module.exports = Irenic; //Irenic is just the name of the engine. This is actually an object housing most of the classes and functions.
But, what if I made some functions outside of the Irenic
object? For example, I redefined setInterval
and setTimeout
functions to track how many timeouts/intervals are active, and now I relized that I wont be able to use them outside of the file the engine is in.
How can I export everything in a file? (I already tried module.exports = this;
, but it didn't work. Exported an empty object.)
Edit 1: I'd like to be able to simply call()
the functions in the file I include the engine in, not do something like exportedObj.call()
.
You could wrap your engine + the functions into an object that you exports.
module.exports = {engine: Irenic, fun: function(){...} ... }