Skip to content

Instantly share code, notes, and snippets.

@jgaskins
Created June 29, 2017 14:04
Show Gist options
  • Save jgaskins/66ccd264794563bdfe5d8eba96ce39b2 to your computer and use it in GitHub Desktop.
Save jgaskins/66ccd264794563bdfe5d8eba96ce39b2 to your computer and use it in GitHub Desktop.
Objects as curried functions
class Foo {
constructor(bar) { this.bar = bar }
getBar() { return this.bar }
setBar(newBar) { this.bar = newBar }
}
function FuncFoo(bar) {
function getBar() { return bar }
function setBar(newBar) { bar = newBar }
// This is our only public API
return { getBar, setBar }
}
const objFoo = new Foo("object")
const funcFoo = FuncFoo("function")
console.log(objFoo.getBar())
console.log(funcFoo.getBar())
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment