title: Object comparison in Javascript using equals and compareTo methods
body: <p>I'm trying to implement custom equality and relational operations using equals and compareTo methods. However, I get wrong results. Please help me figure our where I'm doing wrong.</p>
  
  <pre><code>var Person = function () {
  this.age = null;
  this.name = null;
  };
  
  Person.prototype.equals = function (that) {
      if (this.age === that.age) return true;
      else return false;
      };
  
  Person.prototype.compareTo = function (that) {
      return this.age - that.age;
      };
  
  var p1 = new Person();
  var p2 = new Person();
  
  p1.age = 10;
  p2.age = 20;
  
  document.writeln(p1 &lt; p2); // this should be true but evaluates to false.
  </code></pre>