Skip to content

Instantly share code, notes, and snippets.

@marekpiechut
Last active August 22, 2017 07:23
Show Gist options
  • Save marekpiechut/43edfe73a865f8a36e135a4b1dbecff2 to your computer and use it in GitHub Desktop.
Save marekpiechut/43edfe73a865f8a36e135a4b1dbecff2 to your computer and use it in GitHub Desktop.
Simple factory with object literal
const createMyType = (startVal) => {
let name = "Magic Object"
let magic = 32
let val = startVal
return {
add: (b) => { val += magic + b },
sub: (b) => { val += magic - b },
getVal: () => val
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment