Hey I read at Google article (here) that we need to be careful when using closures.
For example, they gave there this function:
function foo(element, a, b) {
element.onclick = function() { /* uses a and b */ };
}
And I quote:
the function closure keeps a reference to element, a, and b even if it never uses element. Since element also keeps a reference to the closure, we have a cycle that won't be cleaned up by garbage collection.
And I also read an article on the module pattern
, and there is a lot of use in closures
for example if I declare a module like that:
(function () {
var a = function () { };
var b = function () { };
}());
So b
have access to a
, meaning its also save reference to all functions declared on the module.
Is it considered bad practice too?