title: JavaScript best practice, Using closures
body: <p>Hey I read at Google article (<a href="https://google.github.io/styleguide/javascriptguide.xml" rel="nofollow noreferrer">here</a>) that we need to be careful when using closures.<br>
  For example, they gave there this function:</p>
  
  <pre><code>function foo(element, a, b) {
      element.onclick = function() { /* uses a and b */ };
  }
  </code></pre>
  
  <p>And I quote:</p>
  
  <blockquote>
    <p>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.</p>
  </blockquote>
  
  <p>And I also read an article on the <code>module pattern</code> , and there is a lot of use in closures</p>
  
  <p>for example if I declare a module like that:</p>
  
  <pre><code>(function () {
      var a = function () { };
      var b = function () { };
  }());
  </code></pre>
  
  <p>So <code>b</code> have access to <code>a</code> , meaning its also save reference to all functions declared on the module.</p>
  
  <p>Is it considered bad practice too?</p>