Skip to content

Instantly share code, notes, and snippets.

@Luchanso
Forked from alexaivars/setter_pattern.coffee
Last active August 29, 2015 14:10
Show Gist options
  • Save Luchanso/ccc6ada94cc1c176b83f to your computer and use it in GitHub Desktop.
Save Luchanso/ccc6ada94cc1c176b83f to your computer and use it in GitHub Desktop.
Function::define = (prop, desc) ->
Object.defineProperty @prototype, prop, desc
class Person
constructor: (@firstName, @lastName) ->
@define 'fullName',
get: -> "#{@firstName} #{@lastName}"
set: (name) -> [@firstName, @lastName] = name.split ' '
p = new Person 'Robert', 'Paulson'
console.log p.fullName # Robert Paulson
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment