Implement method chaining.
Code:
function multiply(x) {
let multiplication = x;
return {
multiply(num) {
multiplication *= num;
return this;
},
getValue() {
return multiplication;
}
};
}
let result = multiply(1).multiply(5).getValue();
console.log(result);
Output:
5
No comments:
Post a Comment