Chaining
by fredericklim
JavaScript
let ladder = {
step: 0,
up() {
this.step++;
return this;
},
down() {
this.step--;
return this;
},
showStep: function() { // shows the current step
alert( this.step );
}
};
ladder.up().up().down().up().down().showStep();