title: How to load KnockoutJS custom functions with RequireJS?
body: <p>I have a View Model that uses a custom observableArray function for sorting. When I try to run this it says: "...has no methods 'sortByProperty'".</p>
  
  <p>How should I load the handlers.js file to make this work?</p>
  
  <p><strong>handlers.js:</strong></p>
  
  <pre><code>define(['knockout'], function(ko) {
          'use strict';
  
          ko.observableArray.fn.sortByProperty = function (prop, order) {
              this.sort(function (obj1, obj2) {
                  var result;
                  if (obj1[prop] == obj2[prop])
                      result = 0;
                  else if (obj1[prop] &lt; obj2[prop])
                      result = -1;
                  else
                      result = 1;
  
                  return order === "desc" ? -result : result;
              });
          };
  
      });
  </code></pre>
  
  <p><strong>viewmodel.js:</strong></p>
  
  <pre><code>define([
          'knockout',
          'js/extends/handlers'
      ], function(ko) {
          'use strict';
  
          var LabelsModel = function() {
              var self = this;
  
              self.availableLabels = ko.observableArray();
              self.selectedLabel = ko.observable();
              self.sortBy = ko.observable(); // What field to sort by
              self.sortOrder = ko.observable(); // Sort order. asc or desc.
  
              // Returns the labels for the current page
              self.pagedRows = ko.computed(function() {
                  // Sorts the labels
                  return self.availableLabels.sortByProperty(self.sortBy(), self.sortOrder());
              });
  
          };
  
          return LabelsModel;
  
      });
  </code></pre>