1 // ==========================================================================
  2 // Project:   SproutCore Costello - Property Observing Library
  3 // Copyright: ©2006-2011 Strobe Inc. and contributors.
  4 //            Portions ©2008-2011 Apple Inc. All rights reserved.
  5 // License:   Licensed under MIT license (see license.js)
  6 // ==========================================================================
  7 
  8 /**
  9   @class
 10 
 11   Implements some standard methods for comparing objects. Add this mixin to
 12   any class you create that can compare its instances.
 13 
 14   You should implement the compare() method.
 15 
 16   @since SproutCore 1.0
 17 */
 18 SC.Comparable = {
 19 
 20   /**
 21     walk like a duck. Indicates that the object can be compared.
 22 
 23     @type Boolean
 24   */
 25   isComparable: YES,
 26 
 27   /**
 28     Override to return the result of the comparison of the two parameters. The
 29     compare method should return
 30     
 31     <pre>
 32       -1 if a < b
 33        0 if a == b
 34        1 if a > b
 35     </pre>
 36 
 37 
 38     Default implementation raises an exception.
 39 
 40     @param a {Object} the first object to compare
 41     @param b {Object} the second object to compare
 42     @returns {Integer} the result of the comparison
 43   */
 44   compare: function(a, b) {
 45     throw new Error("%@.compare() is not implemented".fmt(this.toString()));
 46   }
 47 
 48 };
 49