var Human = function (coords) {
this.top = coords.top || 0;
this.left = coords.left || 0;
};
Human.prototype = {
go: function (coords) {
this.top += coords.top || 0;
this.left += coords.left || 0;
return this;
},
goUp: function () {
return this.go({top: -1});
},
goDown: function () {
return this.go({top: 1});
},
goLeft: function () {
return this.go({left: -1});
},
goRight: function () {
return this.go({left: 1});
}
};
var vagabond = new Human({
top: 2,
left: 2
});
vagabond.goUp().goLeft().goDown().goDown().goRight();
vagabond.go({
top: 0,
left: 0
});