title: Modifying the bind native function of JavaScript
body: <p>I went through a code snippet today as below:</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 &amp;&amp; oThis
                                   ? this
                                   : oThis,
                                 aArgs.concat(Array.prototype.slice.call(arguments)));
          };
  
      fNOP.prototype = this.prototype;
      fBound.prototype = new fNOP();
  
      return fBound;
    };
  }
  </code></pre>
  
  <p>What I actually got is that I'm building a samsung smart TV application and I found this code in one of the sample app codes. May be the smart tv JavaScript engine doesn't have any bind prototype on the <code>Function</code> object and doesn't support to bind the event. That's why the author tried to create a new bind prototype on the native <code>Function</code> object.</p>
  
  <p>But I'm really not getting rest of the code and what it is really doing here.</p>