title: How to access the observables in custom bindings when using Knockout-ES5
body: <p>If the model properties are ko.observable(), these can be accessed as below within the custom binding.</p>
  
  <pre><code>var observable = valueAccessor();
  </code></pre>
  
  <p>When using Knockout-ES5 plugin how to get hold of the observable within the custom binding? Check the code below and look for comment "How to get propertyName here?"</p>
  
  <p><a href="http://jsfiddle.net/rniemeyer/X82aC/" rel="nofollow">JS Fiddle when not using Knockout-ES plugin</a> courtesy of <a href="http://www.knockmeout.net/2011/07/another-look-at-custom-bindings-for.html" rel="nofollow">Another Look at Custom Bindings for KnockoutJS</a></p>
  
  <p><a href="http://jsfiddle.net/xb6vR/" rel="nofollow">Updated fiddle with model changed to use Knockout-ES plugin</a></p>
  
  <pre><code>ko.bindingHandlers.datepicker = {
      init: function(element, valueAccessor, allBindingsAccessor, viewModel) {
          //initialize datepicker with some optional options
          var options = allBindingsAccessor().datepickerOptions || {};
          $(element).datepicker(options);
  
          //handle the field changing
          ko.utils.registerEventHandler(element, "change", function () {
              var observable = valueAccessor();
              if (!ko.isObservable(observable)) {                
                  console.log("Not Observable");
                  //How to get propertyName here?
                  //ko.getObservable(viewModel, 'propertyName');
                  return;
              }
              observable($(element).datepicker("getDate"));
          });
  
          //handle disposal (if KO removes by the template binding)
          ko.utils.domNodeDisposal.addDisposeCallback(element, function() {
              $(element).datepicker("destroy");
          });
  
      },
      //update the control when the view model changes
      update: function(element, valueAccessor) {
          var value = ko.utils.unwrapObservable(valueAccessor()),
              current = $(element).datepicker("getDate");
  
          if (value - current !== 0) {
              $(element).datepicker("setDate", value);   
          }
      }
  };
  
  var viewModel = {
      myDate: new Date("11/01/2011"),
      setToCurrentDate: function() {
         this.myDate = new Date();   
      }
  };
  
  ko.track(viewModel);
  
  ko.applyBindings(viewModel);
  </code></pre>