Skip to content

Instantly share code, notes, and snippets.

@ssadams11
ssadams11 / attributes.coffee
Created May 21, 2018 13:19
simple way to add getters/setters in Coffeescript
#thanks to https://stackoverflow.com/users/1388302/kwerle
#see https://stackoverflow.com/a/42845509
attribute = (self, name, getterSetterHash) ->
Object.defineProperty self, name, getterSetterHash
class MyClass
constructor: () ->
attribute @, 'foo',
get: -> @_foo ||= 'Foo' # Set the default value