File tree Expand file tree Collapse file tree 2 files changed +6
-4
lines changed
1-js/04-object-basics/04-object-methods/8-chain-calls Expand file tree Collapse file tree 2 files changed +6
-4
lines changed Original file line number Diff line number Diff line change @@ -23,7 +23,7 @@ let ladder = {
2323 }
2424};
2525
26- ladder .up ().up ().down ().up ().down ().showStep (); // 1
26+ ladder .up ().up ().down ().showStep ().down ().showStep (); // shows 1 then 0
2727```
2828
2929We also can write a single call per line. For long chains it's more readable:
3333 .up ()
3434 .up ()
3535 .down ()
36- .up ()
36+ .showStep () // 1
3737 .down ()
38- .showStep (); // 1
38+ .showStep (); // 0
3939```
Original file line number Diff line number Diff line change @@ -28,12 +28,14 @@ ladder.up();
2828ladder .up ();
2929ladder .down ();
3030ladder .showStep (); // 1
31+ ladder .down ();
32+ ladder .showStep (); // 0
3133```
3234
3335Modify the code of ` up ` , ` down ` and ` showStep ` to make the calls chainable, like this:
3436
3537``` js
36- ladder .up ().up ().down ().showStep (); // 1
38+ ladder .up ().up ().down ().showStep (). down (). showStep () ; // shows 1 then 0
3739```
3840
3941Such approach is widely used across JavaScript libraries.
You can’t perform that action at this time.
0 commit comments