I've seen a lot of apps repeatedly use code like :
require("module").function_call(foo); require("module").function_call(foo); require("module").function_call(foo);
with the same module over and over. Is that a bad thing? I would have thought something like:
var mod = require("module"); // ... mod.function_call(foo); mod.function_call(foo); mod.function_call(foo);
would be better if you're using the same module over and over? This is particularly noticeable for modules like "locale".
The Modules page doesn't cover this, but uses the first convention. The entry for require uses the second as the example.
I'd prefer the second (assigning to a variable), but I'd like confirmation that is best.
@andrewg_oz started
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.
I've seen a lot of apps repeatedly use code like :
with the same module over and over. Is that a bad thing? I would have thought something like:
would be better if you're using the same module over and over? This is particularly noticeable for modules like "locale".
The Modules page doesn't cover this, but uses the first convention. The entry for require uses the second as the example.
I'd prefer the second (assigning to a variable), but I'd like confirmation that is best.