Skip to content

Instantly share code, notes, and snippets.

@geraldalewis
Created September 18, 2012 10:59
Show Gist options
  • Save geraldalewis/3742581 to your computer and use it in GitHub Desktop.
Save geraldalewis/3742581 to your computer and use it in GitHub Desktop.
Do does
class Frame
constructor: (@elements) ->
methods = ['remove', 'show', 'hide', 'stop']
for method in methods
do (method) ->
Frame::[method] = ->
element[method]() for element in @elements
class El
constructor: (@name) ->
remove: -> console.log("remove called on #{@name}")
show: -> console.log("show called on #{@name}")
hide: -> console.log("hide called on #{@name}")
stop: -> console.log("stop called on #{@name}")
el1 = new El("El1")
el2 = new El("El2")
el3 = new El("El3")
f = new Frame [el1, el2, el3]
f.remove()
f.show()
f.hide()
f.stop()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment