Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
A small collection of generic CoffeeScript helper functions.
# shorthand wrapper for `console.log`
put = (args...) -> console.log args...
# initialise undefined vars: `[a, b, c] = init 3`
init = (amount) -> undefined for n in [1..amount]
# decorator for defining constructors (see
factory = (mutator) -> (args...) ->
mutator (self = Object.create null), args...
return self
# decorator for defining blessings (see
bless = (mutator) -> (self, args...) ->
mutator self, args...
return self
Employee = factory (self, name, salary) -> = name
self.salary = salary
self.raise = (amount) -> self.salary += amount
addVoice = bless (self) ->
self.greet = ->
put "Hi, my name is #{}."
put "I currently earn $#{self.salary}."
alice = Employee "Alice", 50000
addVoice alice
alice.raise 10000
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.