Skip to content

Instantly share code, notes, and snippets.

@antonkartashov
Last active January 20, 2017 15:26
Show Gist options
  • Save antonkartashov/dfff3eaa5f2404ca8f0fe2fc00cd89f7 to your computer and use it in GitHub Desktop.
Save antonkartashov/dfff3eaa5f2404ca8f0fe2fc00cd89f7 to your computer and use it in GitHub Desktop.
Function.prototype.define = (prop, desc) ->
Object.defineProperty(this.prototype, prop, desc)
class Name
constructor: ({@first, @last}) ->
@define "full",
get: ->
return "#{@first} #{@last}"
set: (value) ->
array = value.split(" ")
@first = array[0]
@last = array[1]
name = new Name
first: "Anton"
last: "Kartashov"
print name.full
# » "Anton Kartashov"
name.full = "Clark Kent"
print name.first
print name.last
# » "Clark"
# » "Kent"
name.last = "Gable"
print name.full
# » "Clark Gable"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment