Merge pull request #2777 from Tofpu/missing-showstep-patch
Included missing showStep methods
This commit is contained in:
commit
cbdb2187c0
2 changed files with 6 additions and 4 deletions
|
@ -23,7 +23,7 @@ let ladder = {
|
|||
}
|
||||
};
|
||||
|
||||
ladder.up().up().down().up().down().showStep(); // 1
|
||||
ladder.up().up().down().showStep().down().showStep(); // shows 1 then 0
|
||||
```
|
||||
|
||||
We also can write a single call per line. For long chains it's more readable:
|
||||
|
@ -33,7 +33,7 @@ ladder
|
|||
.up()
|
||||
.up()
|
||||
.down()
|
||||
.up()
|
||||
.showStep() // 1
|
||||
.down()
|
||||
.showStep(); // 1
|
||||
.showStep(); // 0
|
||||
```
|
||||
|
|
|
@ -28,12 +28,14 @@ ladder.up();
|
|||
ladder.up();
|
||||
ladder.down();
|
||||
ladder.showStep(); // 1
|
||||
ladder.down();
|
||||
ladder.showStep(); // 0
|
||||
```
|
||||
|
||||
Modify the code of `up`, `down` and `showStep` to make the calls chainable, like this:
|
||||
|
||||
```js
|
||||
ladder.up().up().down().showStep(); // 1
|
||||
ladder.up().up().down().showStep().down().showStep(); // shows 1 then 0
|
||||
```
|
||||
|
||||
Such approach is widely used across JavaScript libraries.
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue