title: I can't understand how this javascript function works
body: <p>I was reading the <a href="https://developer.mozilla.org/en/JavaScript/Reference/Global_Objects/Function/bind" rel="noreferrer">function definition of bind</a>, but I can't 100% understand the code as written:</p>
  
  <pre><code>if (!Function.prototype.bind) {
      Function.prototype.bind = function(oThis) {
          if (typeof this !== "function") {
              // closest thing possible to the ECMAScript 5 internal IsCallable function
              throw new TypeError("Function.prototype.bind - what is trying to be bound is not callable");
          }
  
          var aArgs = Array.prototype.slice.call(arguments, 1),
              fToBind = this,
              fNOP = function() {},
              fBound = function() {
                  return fToBind.apply(this instanceof fNOP
                                         ? this 
                                         : oThis || window,
                                       aArgs.concat(Array.prototype.slice.call(arguments)));
              };
  
          fNOP.prototype = this.prototype;
          fBound.prototype = new fNOP();
  
          return fBound;
      };
  }
  </code></pre>
  
  <p>Specifically, I don't get the purpose of <code>fNOP</code>, and I don't understand why <code>fBound</code>'s prototype needs to be set. I am also hung up at the <code>fToBind.apply</code> part (I can't figure out what this represents in this context).</p>
  
  <p>Can someone can explain what is going on here?</p>