title: Refactoring two variants of the same code
body: <p>I'm not a dev, more like a designer. I have a calendar on two different pages, and it should behave differently one these two pages. So I modified the code a bit for it to happen, and it did when I tested it.
  BUT now I have to integrate both these variants together and of course gulp can't compile because of an "already defined" error. So i tried to merge them with a bit of logic but I'm a noob so I need your help please.
  Here are the two bits, and what I tried to do, but I'm sure it's wrong</p>
  
  <pre><code>// Field used on the calendar view.
  var dateFromFilter = $("#dateFromFilter").not($(".unlimitedDateFilter"))
  .fdatepicker($.extend({}, datepickerCommonOptions, {
      onRender: function(date) {
          return date.valueOf() &lt; now.valueOf() ? "disabled" : "";
      }
  }))
  .on("changeDate", function(ev) {
      if (ev.date.valueOf() &gt; dateToFilter.date.valueOf()) {
          var newDate = new Date(ev.date);
          newDate.setDate(newDate.getDate() + 1);
          dateToFilter.update(newDate);
      }
      dateFromFilter.hide();
      $("#dateToFilter")[0].focus();
  })
  .data("datepicker");
  
  
  // Field used on the sales results view
  var dateFromFilter = $("#dateFromFilter.unlimitedDateFilter")
  .fdatepicker($.extend({}, datepickerCommonOptions))
  .on("changeDate", function(ev) {
      if (ev.date.valueOf() &gt; dateToFilter.date.valueOf()) {
          var newDate = new Date(ev.date);
          newDate.setDate(newDate.getDate() + 1);
          dateToFilter.update(newDate);
      }
      dateFromFilter.hide();
      $("#dateToFilter")[0].focus();
  })
  .data("datepicker");
  </code></pre>
  
  <p>My try : </p>
  
  <pre><code>var dateFromFilter = $("#dateFromFilter")
  
  if ($("dateFromFilter").hasClass(unlimitedDateFilter))  {
      $.fdatepicker($.extend({}, datepickerCommonOptions))
  }
  else    {  
      $.fdatepicker($.extend({}, datepickerCommonOptions, {
          onRender: function(date) {
              return date.valueOf() &lt; now.valueOf() ? "disabled" : "";
          }
      }))
  }
  
  $.on("changeDate", function(ev) {
      if (ev.date.valueOf() &gt; dateToFilter.date.valueOf()) {
          var newDate = new Date(ev.date);
          newDate.setDate(newDate.getDate() + 1);
          dateToFilter.update(newDate);
      }
      dateFromFilter.hide();
      $("#dateToFilter")[0].focus();
  })
  .data("datepicker");
  </code></pre>
  
  <p>Thank you for your help</p>
  
  <p>EDIT : </p>
  
  <p>Thank you for your suggestions, I tried to put the condition in the onRender, but it doesn't work. I think I need to encapsulate the onRender itself in the condition, but I have no idea about how the syntax should be.</p>
  
  <pre><code>// Field used on the sales results view
      var dateFromFilter = $("#dateFromFilter")
      .fdatepicker($.extend({}, datepickerCommonOptions, {
          onRender: function(date) {
              if (!$("dateFromFilter").hasClass("unlimitedDateFilter")) {
                  return date.valueOf() &lt; now.valueOf() ? "disabled" : "";
              }
          }
      }))
      .on("changeDate", function(ev) {
          if (ev.date.valueOf() &gt; dateToFilter.date.valueOf()) {
              var newDate = new Date(ev.date);
              newDate.setDate(newDate.getDate() + 1);
              dateToFilter.update(newDate);
          }
          dateFromFilter.hide();
          $("#dateToFilter")[0].focus();
      })
      .data("datepicker");
  </code></pre>