开发者

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

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜