en.javascript.info/1-js/4-object-basics/03-object-methods/8-chain-calls/solution.md
Ilya Kantor 4c531b5ae7 ok
2016-07-31 00:28:27 +03:00

40 lines
506 B
Markdown

The solution is to return the object itself from every call.
```js run
let ladder = {
step: 0,
up() {
this.step++;
*!*
return this;
*/!*
},
down() {
this.step--;
*!*
return this;
*/!*
},
showStep() {
alert( this.step );
*!*
return this;
*/!*
}
}
ladder.up().up().down().up().down().showStep(); // 1
```
We also can write a single call per line. For long chains it's more readable:
```js
ladder
.up()
.up()
.down()
.up()
.down()
.showStep(); // 1
```