Just got back from a holiday and I have a million e-mails and posts to get through, so sorry for not reading this fully, but this might help:
Modules can be used from another module
Modules are only 'loaded in' once, even if used multiple times. If you put console.log in the main scope of a module, it will only be called once. But it'll be called right at the start, not when you first do require.
If your module is var A = {}; exports.A = A;, every time you require that module you will get access to the same version of A
The order of loading should be correct (i think) - that is, if A requires B, B is loaded before A.
Modules are executed in their own scope (called module IIRC). If you want to stick stuff in the global scope I think you can still use global, but that's probably frowned upon.
Espruino is a JavaScript interpreter for low-power Microcontrollers. This site is both a support community for Espruino and a place to share what you are working on.
Just got back from a holiday and I have a million e-mails and posts to get through, so sorry for not reading this fully, but this might help:
console.log
in the main scope of a module, it will only be called once. But it'll be called right at the start, not when you first dorequire
.var A = {}; exports.A = A;
, every time you require that module you will get access to the same version ofA
module
IIRC). If you want to stick stuff in the global scope I think you can still useglobal
, but that's probably frowned upon.