function rectangle(x, y, w, h) { ... existing code here ... } rectangle.prototype.intersects = function(rect) { return !( rect.x > (this.x + this.w) || (rect.x + rect.w) < this.x || rect.y > (this.y + this.h) || (rect.y + rect.h) < this.y); }