title: Is it good practice to prototype a JavaScript 'equals' method for custom object declarations, and if so how?
body: <p>I'm trying to create a set of re-usable objects in javascript and some of the managed-framework paradigms (like .NET) don't directly translate.</p>
  
  <p>For instance, there is no global <code>getType()</code> method or its equivalent, and there is no default <code>equals()</code> prototype function on Object that even just does a basic reference comparison.</p>
  
  <p>So if I was going to go about creating object definitions, what is the best way to write the comparison function prototype?</p>
  
  <p>e.g. if I started along the lines of the below, am I headed in the right direction or setting myself up for some pain later?</p>
  
  <p>EDIT: Placed code on same line as return as per comment suggestion</p>
  
  <pre><code>function Car(make, model, colour) {
      this.make = make;
      this.model = model;
      this.colour = colour;
  }
  
  Car.prototype.equals = function(otherCar) {
      // Check that 'otherCar' really is a 'Car' ?
      // otherwise the property comparison code below with throw an exception, right?
      // How?
  
  
      // I could just use try / catch, but that could be 'expensive'?
  
      // Property-for-property comparison
  
  
      try {
  
          return this.make === otherCar.make
              &amp;&amp; this.model === otherCar.model
              &amp;&amp; this.colour === otherCar.colour;
  
      } catch(err) {
  
          return false;
  
      }
  }
  </code></pre>