title: when to use .bind(this) in knockoutjs prototype
body: <p>I am learning knockout.js and finding a lot of interesting and useful samples on jsfiddle very. I am looking at some knockout.js samples where it uses object.prototype to add methods to a viewmodel object. In some samples it also defines a method in the viewmodel and use .bind(this) while in other samples it doesn't do this. So I don't understand when you have to use .bind(this) with the methods added using prototype? </p>
  
  <p>For example, <a href="http://jsfiddle.net/rniemeyer/csxAL/" rel="nofollow">this sample</a> adds some methods to the ViewModel object using prototype but it also defines those methods in the viewmodel and then uses .bind(this). I don't understand why it needs to do this as I found <a href="http://jsfiddle.net/rniemeyer/x57Lv/" rel="nofollow">another sample</a> where it doesn't declare the same method in the viewmodel and uses .bind(this). </p>
  
  <pre><code>var ViewModel = function(items) {
      this.selectItem = this.selectItem.bind(this);
      this.acceptItem = this.acceptItem.bind(this);
      this.revertItem = this.revertItem.bind(this);
  }
  ko.utils.extend(ViewModel.prototype, {
      //select an item and make a copy of it for editing
      selectItem: function(item) {
          this.selectedItem(item);
          this.itemForEditing(new Item(ko.toJS(item)));
      },
  
      acceptItem: function(item) {
          if (item.errors().length == 0) { //Check if ViewModel has any errors
              alert('Thank you.');
          var selected = this.selectedItem(),
              edited = ko.toJS(this.itemForEditing()); //clean copy of edited
  
          //apply updates from the edited item to the selected item
          selected.name.update.call(selected, edited);
  
          //clear selected item
          this.selectedItem(null);
          this.itemForEditing(null);
          }
  
          else {
              alert('Please check your submission.');
              item.errors.showAllMessages();
          }
      },
  
      //just throw away the edited item and clear the selected observables
      revertItem: function() {
          this.selectedItem(null);
          this.itemForEditing(null);
      }
  });
  </code></pre>