I've just been using exports = ClassName; which seems to be working fine.
Yes, that's fine if you want just one class in a module.
e.g. can more than one class exist in any one module? exports.ClassName = ClassName; exports.ClassNameDiff = ClassNameDiff;
Yes, that's right. If you want two classes you can do it like that.
Modules aren't particularly magic or clever - whatever is in exports after the module has executed is available when you then use require, so you treat it just like you would any other variable.
I've seen in some of your code you do:
exports = foo;
exports = bar;
exports = baz;
But in that case, foo and bar get lost. After the code has executed, exports is equal to baz, so that's what gets exported.
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.
Yes, that's fine if you want just one class in a module.
Yes, that's right. If you want two classes you can do it like that.
Modules aren't particularly magic or clever - whatever is in
exports
after the module has executed is available when you then userequire
, so you treat it just like you would any other variable.I've seen in some of your code you do:
But in that case,
foo
andbar
get lost. After the code has executed,exports
is equal tobaz
, so that's what gets exported.