I am wondering what is the memory size for closing JavaScript?
What does this amount depend on?
The first obvious factor in closing memory consumption is the number of variables it captures and their sizes.
Well, suppose we have a simple closure:
var counter = (function () {
var num = 0;
return function () {
return ++num;
}
}());
How much memory will it take?
If it’s hard to say the exact numbers, I would like to know at least that amount. Is it 10, 100 bytes or more?
Is this any different than the JavaScript implementation?
I hope that the answers to these questions, especially with some numbers, will help me and other readers clarify:
Is it good practice to use closure as much as you need?
Or you should use it with caution and avoid it whenever possible, because the overhead of using a closure can probably outweigh the benefits it gives.
In other words, I hope that I can better understand which situations are worth using closure and which are not.
1:
@MaximillianLaumeister , , :
? , , ? JavaScript?
, :