require() best practices #1603
Unanswered
espruino-discuss
asked this question in
JavaScript
Replies: 2 comments
-
Posted at 2022-03-28 by @gfwilliams The second method is a smidge faster, but not too much - and it does use one more variable, so really it's personal opinion. Once the module has been loaded it's 'cached' and subsequent calls to |
Beta Was this translation helpful? Give feedback.
0 replies
-
Posted at 2022-03-29 by andrewg_oz Thanks. That's all good to know. |
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
Posted at 2022-03-26 by andrewg_oz
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.
Beta Was this translation helpful? Give feedback.
All reactions