Skip to content

Instantly share code, notes, and snippets.

@PyroLagus
Created February 12, 2017 04:26
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 PyroLagus/150e69ff775e22d101f3a4328c5950ad to your computer and use it in GitHub Desktop.
Save PyroLagus/150e69ff775e22d101f3a4328c5950ad to your computer and use it in GitHub Desktop.
function Point(x, y) {
this.x = x;
this.y = y;
}
Point.prototype = {
west: function() {
return new this(this.x-1, this.y);
},
east: function() {
return new this(this.x+1, this.y);
},
north: function() {
return new this(this.x, this.y-1);
},
south: function() {
return new this(this.x, this.y+1);
},
moveWest: function() {
this.x--;
},
moveEast: function() {
this.x++;
},
moveNorth: function() {
this.y--;
},
moveSouth: function() {
this.y++;
}
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment