Created
January 8, 2013 03:24
-
-
Save ichord/4480923 to your computer and use it in GitHub Desktop.
javascript Decorator pattern.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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