4 ms·
Avoid globals at all costs - use IIFE [1] instead, wrapping your function in parenthesis and invoking it right away. [1] https://developer.mozilla.org/en-US/do
by mmastrac 4y ago
Avoid globals at all costs - use IIFE [1] instead, wrapping your function in parenthesis and invoking it right away.
[1] https://developer.mozilla.org/en-US/docs/Glossary/IIFE https://developer.mozilla.org/en-US/docs/Glossary/IIFE
- recursive 4y agoIf you have access to `let`, you can just put `let` declarations into a block. No need for a function to establish scope.
- an1sotropy 4y agoWhen, today, does it make more sense to organize things around IIFEs and not ES6 modules?
- throw_m239339 4y ago{ let foo = 1 }; // foo is undefined here
- jbverschoor 4y agoAnd then get coworkers to remove it because they don’t understand that you can create scopes like that
- WorldMaker 4y agoIt's 2022, you can use ES2015 modules now. We can leave IIFE to the dustbin of the past.