52deco 中文文档教程
52deco v1.0.1
在不进行转译的情况下使用装饰器
52deco 是一个小型实用程序,用于执行与 ESNext 装饰器相同的操作。 Decorators 提案已经发生了很大变化,目前唯一可用的 babel transpilation 已经过时且不可靠。 该工具支持使用具有简单辅助功能的装饰器。
:cd: Install
通过 npm:
npm install --save 52deco
:book: Usage
在方法装饰器
const deco = requrie('52deco')
class Foo {
method () { ... }
}
deco.method(decorator, Foo, 'method')
的情况下: 以上等同于:
class Foo {
@decorator
method () { ... }
}
在类装饰器
const deco = require('52deco')
class Foo {
...
}
deco.class(decorator, Foo)
的情况下: 以上等同于:
@decorator
class Foo {
...
}
Note
有 babel 转换 babel-plugin-transform-decorators-legacy。 但是,这不符合当前规范并且不可靠。
Origin
请参阅:https://splatoonwiki.org/wiki/.52
License
GalDeco MIT
52deco v1.0.1
Use decorator without transpilation
52deco is a small utility for performing the same operation what ESNext decorators do. Decorators Proposal has been changing a lot and the only babel transpilation available today is outdated and not reliable. This tool supports using decorator with simple helper function.
:cd: Install
Via npm:
npm install --save 52deco
:book: Usage
In case of method decorator:
const deco = requrie('52deco')
class Foo {
method () { ... }
}
deco.method(decorator, Foo, 'method')
The above is equivalent of:
class Foo {
@decorator
method () { ... }
}
In case of class decorator:
const deco = require('52deco')
class Foo {
...
}
deco.class(decorator, Foo)
The above is equivalent of:
@decorator
class Foo {
...
}
Note
There is the babel transform babel-plugin-transform-decorators-legacy. However that doesn't follow the current spec and not reliable.
Origin
See: https://splatoonwiki.org/wiki/.52GalDeco
License
MIT