У вас хэш-мэпа с функциями, а не объект. То есть вам нужно из функции возвращать экземпляр вашего хэш мэпа или следить за тем что бы контекст вызова сохранялся
Но лучше так:
http://learn.javascript.ru/object-methods#функция-...function Human(x, y) {
this.x = x;
this.y = y;
}
Human.prototype = {
goUp: function () {
this.y++;
return this;
}
goDown: function () {
this.y--;
return this;
}
// ...
}
Так же можно отDRY-ить код:
function coordsChangerFactory(prop, direction) {
return function () {
// тут можно добавить валидацию, мол что бы не вылазить за пределы поля
this[prop] += direction;
return this;
}
}
function Human(x, y) {
this.x = x;
this.y = y;
}
Human.prototype = {
goUp: coordsChangerFactory('y', +1),
goDown: coordsChangerFactory('y', -1),
goLeft: coordsChangerFactory('x', -1),
goRight: coordsChangerFactory('x', +1)
}
var man = new Human(4, 4);
man.goDown().goRight();
console.log('Coords is %dx%d', man.x, man.y); // Coords is 5x3