title: bind a function to another function in javascript
body: <p>I have a function in javascript </p>
  
  <pre><code>function foo(callback) {
      console.log("Hello");
      callback();
  }
  </code></pre>
  
  <p>and another function </p>
  
  <pre><code>function bar() {
    console.log("world");
  }
  </code></pre>
  
  <p>and I want to make a function <code>FooBar</code></p>
  
  <pre><code>FooBar = foo.bind(this, bar);
  </code></pre>
  
  <p>This works fine, however what I'm actually trying to do is create a <a href="https://stackoverflow.com/questions/17130520/writing-a-function-queue-in-javascript/17130540#17130540">function queue</a>, and often I will have to bind a none function parameter before binding a callback, as in the following example </p>
  
  <pre><code>function foo() {
      console.log(arguments[0]);
      var func = arguments[1];
      func();
  }
  
  function bar() {
      console.log("world");
  }
  
  foo.bind(this, "hello");
  var FooBar = foo.bind(this, bar);
  
  FooBar();
  </code></pre>
  
  <p>which produces this error </p>
  
  <pre><code>[Function: bar]
  
  TypeError: undefined is not a function
  </code></pre>
  
  <p>How can a I bind a function to another function once it has been bound to other none function types?</p>