Decorators on functions

三世轮回 提交于 2019-12-02 20:01:54
Axel Rauschmayer

To execute a decorator, you evaluate an expression and doing that prevents hoisting (even for a variable declaration, the right-hand side of an assignment stays put). Therefore, it is not compatible with function declarations being hoisted.

As a work-around, I suggested that function expressions, generator function expressions and arrow functions could be enabled to be decorated:

const func = @someDecorator('abc') (x, y) => { return x + y };

Alas, that wasn’t met with much enthusiasm: Decorators for functions

Leonid Beschastny

You certainly have a point here.

But as neo_blackcap pointed out, function decorator are not part of the ES7 decorators draft.

So, the best thing you can do is to start discussion on the corresponding tracker to attract community attention to your proposal.

ES7 decorators are on their first stage of development second stage of development, meaning that their API is still under development and could undergo any change.

I think the problem is function decorator has not been ES7 draft.

Of course, you still can implement your function decorator by yourself

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!