Last active
December 13, 2015 20:49
-
-
Save pyykkis/4973188 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
# 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