up
This commit is contained in:
parent
5372c18379
commit
3defacc09d
314 changed files with 1761 additions and 1704 deletions
|
@ -0,0 +1,40 @@
|
|||
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
|
||||
```
|
||||
|
Loading…
Add table
Add a link
Reference in a new issue