egoist
8/10/2015 - 3:30 PM

Extended-parameters.ls

class Person
  # defaults @name to [], and assigns the first element
  set-first-name: (@[]names.0) ->
  
  # defaults @name to [], and adds the element (* being the array's length)
  add-name: (@[]names[*]) ->
  
  # defaults @hair to {}, and assigns color
  set-hair-color: (@{}hair.color) ->







p = new Person
p.hair # undefined
p.set-hair-color "#8b0000"
p.hair.color # "#8b0000"

p.names # undefined
p.add-name 'George'
p.add-name 'Jean'
p.names # ["George", "Jean"]
p.set-first-name "Paul"
p.names # ["Paul", "Jean"]