Skip to main content

我可以使用装饰器吗?

一些流行的库在其文档中使用 decorators

¥Some popular libraries use decorators in their documentation.

Create React App 目前有意不支持装饰器语法,因为:

¥Create React App intentionally doesn’t support decorator syntax at the moment because:

  • 这是一个实验性的提案,可能会发生变化(事实上,它已经改变过一次,并且还会再次改变)。

    ¥It is an experimental proposal and is subject to change (in fact, it has already changed once, and will change again).

  • 大多数库目前仅支持该提案的旧版本 - 这永远不会成为标准。

    ¥Most libraries currently support only the old version of the proposal — which will never be a standard.

然而,在许多情况下,你可以在没有装饰器的情况下重写基于装饰器的代码并获得相同的结果。

¥However in many cases you can rewrite decorator-based code without decorators and achieve the same result.

请参考这两个线程以供参考:

¥Please refer to these two threads for reference:

当规范推进到稳定阶段时,Create React App 将添加装饰器支持。

¥Create React App will add decorator support when the specification advances to a stable stage.