Skip to content

Instantly share code, notes, and snippets.

@ichord
Created January 8, 2013 03:24
Show Gist options
  • Save ichord/4480923 to your computer and use it in GitHub Desktop.
Save ichord/4480923 to your computer and use it in GitHub Desktop.
javascript Decorator pattern.
class Demo
@filter: (func, args...) ->
console.log "hello"
(args...) ->
console.log this, "before filter", args
re = func.apply(this, args)
console.log "after filter", re.hi "ahahahha"
constructor: ->
@content = "waht"
# FIXME: using class name is ugly.
this.say = Demo.filter this.say
say: (content) ->
console.log content
this
hi: (content) ->
console.log content
this
demo = new Demo
demo.say "hello"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment