title: Javascript: TypeError: callback is not a function
body: <p>Pulling my hair out here trying to understand the infuriating nuances of Javascript.  Hopefully some JS guru can take a gander, point and go, &quot;well, there's yer problem...&quot;.</p>
  <p>Here's a slimmed down sample of the problem:</p>
  <pre><code>var Parent = (function () {
      var func1 = function () {
          func2(function (res) {
              console.log(res);
          });
      };
  
      var func2 = function (callback) {
          callback('abc');
      };
  
      return {
          init: function () {
              func1();
              func2();
          }
      };
  })();
  </code></pre>
  <p>Call with <code>Parent.init();</code></p>
  <p>This fails with the error:</p>
  <pre><code>Uncaught TypeError: callback is not a function
      at check2 (&lt;anonymous&gt;:9:9)
      at Object.init (&lt;anonymous&gt;:15:13)
      at &lt;anonymous&gt;:1:8
  </code></pre>
  <p>What's getting me, is that if I comment out the enclosing code, like so, then it works as expected:</p>
  <pre><code>// var Parent = (function () {
      var func1 = function () {
          func2(function (res) {
              console.log(res);
          });
      };
  
      var func2 = function (callback) {
          callback('abc');
      };
  
      // return {
      //     init: function () {
      //         func1();
      //         func2();
      //     }
      // };
  // })();
  </code></pre>
  <p>...and call with <code>func1();</code></p>
  <p>Result:</p>
  <pre><code>abc
  </code></pre>
  <p>What am I missing?</p>
  <p>Thanks</p>