built-in-decorators

0.1.0 • Public • Published

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.

Readme

Keywords

none

Package Sidebar

Install

npm i built-in-decorators

Weekly Downloads

2

Version

0.1.0

License

MIT

Unpacked Size

14.8 kB

Total Files

7

Last publish

Collaborators

  • timhall