Created
June 29, 2017 14:04
-
-
Save jgaskins/66ccd264794563bdfe5d8eba96ce39b2 to your computer and use it in GitHub Desktop.
Objects as curried functions
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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