importance: 2
There's a ladder object that allows you to go up and down:
d78b01e9833009fab534462e05c03cffc51bf0e3
let ladder = {
step: 0,
up() {
this.step++;
},
down() {
this.step--;
},
showStep: function() { // affiche l'étape en cours
alert( this.step );
}
};<<<<<<< HEAD Maintenant, si nous devons faire plusieurs appels en séquence, nous pouvons le faire comme ceci :
Now, if we need to make several calls in sequence, we can do it like this:
d78b01e9833009fab534462e05c03cffc51bf0e3
ladder.up();
ladder.up();
ladder.down();
ladder.showStep(); // 1
ladder.down();
ladder.showStep(); // 0Modify the code of up, down, and showStep to make the calls chainable, like this:
d78b01e9833009fab534462e05c03cffc51bf0e3
ladder.up().up().down().showStep().down().showStep(); // shows 1 then 0Such an approach is widely used across JavaScript libraries.
d78b01e9833009fab534462e05c03cffc51bf0e3