title: How to implement a multi-level sort in comparator in Backbone.js/underscore.js?
body: <p>Imagine a Model/Collection like:</p>
  
  <pre><code>var AModel = Backbone.Model.extend({
      defaults: {
          a: 'a string',
          b: 'another string',
          c: 'yet another string'
      }
  });
  
  var ACollection = Backbone.Collection.extend({
      model: AModel,
      comparator: function(amodel) {
          ...
      }
  });
  </code></pre>
  
  <p>How could I write a comparator to implement a multi-level sort?  I'd like to sort by <code>AModel</code>'s <code>a</code> attribute, then by its <code>b</code> attribute, and then by its <code>c</code> attribute.</p>
  
  <p>I've hacked together a comparator that looks something like this, but I want to know if there is a better/smarter way?</p>
  
  <pre><code>comparator: function(amodel) {
      var s = '',
          assumed_max_length_of_any_attribute = 30;
  
      s += amodel.get('a');
      while (s.length &lt; assumed_max_length_of_any_attribute) {
          s += ' ';
      }
  
      s += amodel.get('b');
      while (s.length &lt; assumed_max_length_of_any_attribute) {
          s += ' ';
      }
  
      s += amodel.get('c');
      while (s.length &lt; assumed_max_length_of_any_attribute) {
          s += ' ';
      }
  
      return s;
  }
  </code></pre>
  
  <p>Then, <code>s</code> becomes properly padded with spaces and should be in "lexical" order with multiple levels.  But it all feels very gross compared to the beauty of python's stable multi-level sort (if somehow the above had analogous equivalents in python):</p>
  
  <pre><code>collection.sort(key=lambda x: x.get('c'))
  collection.sort(key=lambda x: x.get('b'))
  collection.sort(key=lambda x: x.get('a'))
  </code></pre>
  
  <p>Is there a better way?</p>