Skip to content

Instantly share code, notes, and snippets.

@anil-pace
Created August 9, 2020 03:41
Show Gist options
  • Select an option

  • Save anil-pace/e1d1ba4377f273b2d8d1348d900ff46a to your computer and use it in GitHub Desktop.

Select an option

Save anil-pace/e1d1ba4377f273b2d8d1348d900ff46a to your computer and use it in GitHub Desktop.
Chaining in JS
var obj = {
result: 0,
addNumber: function (a, b) {
this.result = a + b;
return this;
},
multiplyNumber: function (a) {
this.result = this.result * a;
return this;
},
divideNumber: function (a) {
this.result = this.result / a;
return this;
}
}
obj.addNumber(10, 20).multiplyNumber(3).divideNumber(5);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment