Skip to content

Instantly share code, notes, and snippets.

@tangzero
Forked from howlingblast/gist:5814547
Created December 3, 2013 20:29
Show Gist options
  • Save tangzero/7776967 to your computer and use it in GitHub Desktop.
Save tangzero/7776967 to your computer and use it in GitHub Desktop.
Function::property = (prop, desc) ->
Object.defineProperty @prototype, prop, desc
class Person
constructor: (@firstName, @lastName) ->
@property 'fullName',
get: -> "#{@firstName} #{@lastName}"
set: (name) -> [@firstName, @lastName] = name.split ' '
p = new Person 'Leroy', 'Jenkins'
console.log p.fullName # Leroy Jenkins
p.fullName = 'Leroy Monkey'
console.log p.lastName # Monkey
console.log p.fullName # Leroy Monkey
p.lastName = 'Jenkins'
console.log p.fullName
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment