Skip to content

Instantly share code, notes, and snippets.

@johnstew
Created February 11, 2013 15:01
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save johnstew/4754929 to your computer and use it in GitHub Desktop.
Save johnstew/4754929 to your computer and use it in GitHub Desktop.
Common Object Methods
function Rectangle(w,h){
this.width = w;
this.height = h;
}
/* Basic area function.*/
Rectangle.prototype.area = function(){
return this.width * this.height;
}
/* Common Object Methods*/
/*
Write an equals() method to compare your objects equality to each other. JavaScript's
built in equals() method just checks to see if you are referring to the same object, not
if the object values equal each other.
*/
Rectangle.prototype.equals = function(oRect){
return (this.width == oRect.width && this.height == oRect.height);
}
/*
Write a compateTo() method also to compare your objects to each other.
*/
Rectangle.prototype.compareTo = function(oRect){
return (this.area() - oRect.area());
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment