Created
February 11, 2013 15:01
-
-
Save johnstew/4754929 to your computer and use it in GitHub Desktop.
Common Object Methods
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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