en.javascript.info/1-js/6-objects-more/1-object-methods/8-chain-calls/solution.md
2015-03-10 12:36:58 +03:00

23 lines
516 B
Markdown

Решение состоит в том, чтобы каждый раз возвращать текущий объект. Это делается добавлением `return this` в конце каждого метода:
```js
//+ run
var ladder = {
step: 0,
up: function() {
this.step++;
return this;
},
down: function() {
this.step--;
return this;
},
showStep: function() {
alert( this.step );
return this;
}
}
ladder.up().up().down().up().down().showStep(); // 1
```