Skip to content

Instantly share code, notes, and snippets.

@pyykkis
Last active December 13, 2015 20:49
Show Gist options
  • Save pyykkis/4973188 to your computer and use it in GitHub Desktop.
Save pyykkis/4973188 to your computer and use it in GitHub Desktop.
# Do something before the method
before = (decorator) -> (method) -> ->
decorator.apply this, arguments
method.apply this, arguments
# Do something after the method
after = (decorator) -> (method) -> ->
method.apply this, arguments
decorator.apply this, arguments
# Decorate methods to support jQuery-like chaining
chainable = after -> this
class Context
constructor: (@el) ->
detach: chainable ->
@el.remove()
attach: chainable ->
@el.appendTo(parent)
render: chainable (models, directives, options) ->
@el.render(models, directives, options)
#...
context
.detach()
.render(models, directives, options)
.attach()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment