Skip to content

Instantly share code, notes, and snippets.

@juice49
Created June 6, 2019 18:52
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
Star You must be signed in to star a gist
Embed
What would you like to do?
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