built-in-decorators
v0.1.0
Published
Legacy decorators for proposed built-in decorators
Downloads
0
Readme
Built-in Decorators
Based on the Fall 2019, Stage 2 Decorators Proposal, these decorators are defined as "built-in decorators that can either be used directly, or can be used as a basis to define other decorators."
@wrap
The @wrap decorator can be used on a method to pass the function through another function. For example:
class C {
@wrap(f) method() {}
}is roughly equivalent to the following:
class C {
method() {}
}
C.prototype.method = f(C.prototype.method);@wrap can also be used on a class to wrap the entire class:
@wrap(f)
class C {}is roughly equivalent to:
class C {}
C = f(C);@register
The @register decorator schedules a callback to run after the class is created.
class C {
@register(f) method() {}
}is roughly equivalent to:
class C {
method() {}
}
f(C, 'method');@initialize
Not currently implemented, this proved difficult with the legacy decorators approach.
