Merge pull request #2777 from Tofpu/missing-showstep-patch

Included missing showStep methods
This commit is contained in:
Ilya Kantor 2021-12-13 13:16:20 +03:00 committed by GitHub
commit cbdb2187c0
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 6 additions and 4 deletions

View file

@ -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
```

View file

@ -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.