Skip to content

Instantly share code, notes, and snippets.

@juice49
Created June 6, 2019 18:52
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save juice49/b9cd22edb5abb30d1fbf149b45aa716e to your computer and use it in GitHub Desktop.
Save juice49/b9cd22edb5abb30d1fbf149b45aa716e to your computer and use it in GitHub Desktop.
Fluent calculator
class Calculator {
constructor (value = 0) {
this.value = value
}
add (value = 0) {
this.value += value
return this
}
multiply (value = 0) {
this.value *= value
return this
}
}
const value = new Calculator(7)
value
.add(7)
.add(10)
.multiply(2)
console.log(value.value)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment