Skip to content Skip to sidebar Skip to footer

Are Namespaced Functions Reevaluated On Every Call?

In this example: function foo () { function bar () { return 'foo bar'; } bar(); } foo(); Is bar reevaluated for every x times that foo is called? Conversely: function ba

Solution 1:

Short answer: Yes.

As is mentioned in the comments for your question, everything in the function body is run whenever you call the function.

The second example is faster because it only has to call a previously initialised function, whereas in your first example, the code has to re-initialise the function every time. Basically, it's having to repeat the work each time foo() is called, which takes up extra processing time.

Post a Comment for "Are Namespaced Functions Reevaluated On Every Call?"