Binding an specific context to an event handler
<p>I am just learning JavaScript and reading from that Ninja Secrets book and this is how he has done it to bind a click event to a button.  So as I am just a beginner and learning I wanted to do is it the best and final way of doing this ( adding click handler to a button ) or he has just used this as an example to demonstrate closures and this is NOT how in real world it is done.</p>

<pre><code>  &lt;body&gt;
    &lt;button id="test"&gt;Click Me!&lt;/button&gt;

    &lt;script&gt;
      function bind(context,name){                                 //#1
        return function(){                                         //#1
          return context[name].apply(context,arguments);           //#1
        };                                                         //#1
      }                                                            //#1

      var button = {
        clicked: false,
        click: function(){
          this.clicked = true;
          assert(button.clicked,"The button has been clicked");
          console.log(this);
        }
      };

      var elem = document.getElementById("test");
      elem.addEventListener("click",bind(button,"click"),false);     //#2

    &lt;/script&gt;

  &lt;/body&gt;
</code></pre>
