3 ms·
It appears they are warning about using closures everywhere to avoid memory leaks. > are they suggesting that every function be exported? No. Just export the
by akbar501 12y ago
It appears they are warning about using closures everywhere to avoid memory leaks.
> are they suggesting that every function be exported?
No. Just export the functions that are used outside of the module. Other functions can be private to the module.
> Why is it better to have your functions not contain other functions (or is it not be contained?)
1. It can make the code clearer
2. It eliminates one source of memory leaks
3. It allows the V8 runtime to optimize more of your code. There is a function length limit (including comments) before V8 will no longer optimize a function.
module.exports = function fOne() {
function fTwo() {
}
do something...
fTwo();
}
Can become:
function fTwo() {
}
module.exports = function fOne() {
do something...
fTwo();
}