I have a function a, which will be executed many times (thousands).
Inside the a function there is a util function, which is ONLY used inside a.
Now I have two options:
First, put the util inside a. It won't "pollute" the outside scope but will be declared once every time a is called.
Second, put the util outside a. It will do the reverse.
Which one is better for performance?
Option 1:
while(xx){
a();
}
function a(){
util();
function util(){
// will only stay inside a()
// but will be declared everytime when a is called.
}
}
Option 2:
while(xx){
a();
}
function a(){
util();
}
function util(){
// only declare once but will be accessed by all other scope outside a().
}