Skip to content

Instantly share code, notes, and snippets.

@husa
Last active August 29, 2015 14:10
Show Gist options
  • Save husa/fba1109aad16b22da258 to your computer and use it in GitHub Desktop.
Save husa/fba1109aad16b22da258 to your computer and use it in GitHub Desktop.
Simple Decorator
class Decorator
constructor: ({pre, post}) ->
return (func) ->
(args...) ->
args = pre?(args...) or args
ret = func(args...)
post?(ret) or ret
currency = new Decorator({post : (a) -> '$' + a})
tax = currency (x) -> x * 0.2
console.log tax 100
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment