Skip to content

Instantly share code, notes, and snippets.

Created March 18, 2014 17:59
Show Gist options
  • Save anonymous/9625705 to your computer and use it in GitHub Desktop.
Save anonymous/9625705 to your computer and use it in GitHub Desktop.
var Point = function (xloc,yloc) {
var x = xloc;
var y = yloc;
var constructor = function(){ }
constructor.prototype.getX = function() { return x; }
constructor.prototype.getY = function() { return y; }
constructor.prototype.translate = function(xdelta,ydelta) {
x = x + xdelta;
y = y + ydelta;
}
constructor.prototype.toString = function() {
return "(" + x + "," + y + ")";
}
return new constructor();
}
var Shape = function (point) {
var anchor = point;
var constructor = function() { }
constructor.prototype.move = function(xdelta,ydelta) {
anchor.translate(xdelta,ydelta);
}
constructor.prototype.getAnchor = function() {
return anchor;
}
return new constructor();
}
var Rectangle = function (point,width,height) {
var width = width;
var height = height;
var constructor = function() {}
constructor.prototype = new Shape(point);
constructor.prototype.area = function() {
return width*height;
}
return new constructor();
}
module.exports.Point = Point;
module.exports.Shape = Shape;
module.exports.Rectangle = Rectangle;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment