Conditional creation of closures in JavaScript
Say I have a function like this:
f开发者_如何学编程unction wrap_function(fnInput)
{
if (somecondition)
{
return function() {
// Simplified example, in reality doing more stuff in here
fnInput.apply(this, arguments)
}
}
else
{
return fnInput;
}
}
I'm assuming that if somecondition
is false this function won't create a closure and therefore won't have performance/memory impacts associated with closures.
Is this correct?
If somecondition
is false a closure will not be created. You're using the loosely typed nature of javascript in your example
精彩评论