Ok couple useful examples:
typescript
/* [built-in] hint for compiler which should always inline this func.
* Simpilar to `inline` in other langs
*/
@inline
function toDeg(x: number): number {
return x * (180 / Math.PI);
}
example below just proof of concept. Not supported yet by AS:
typescript
/* [built-in] similar to `constexpr` in C++.
* Force expression evaluation during compilation. Valid only for constant arguments.
*/
@precompute // or @const ?
function fib(x: number): number {
if (n <= 1) return n;
return fib(n - 1) + fib(n - 2);
}
typescript
/* [built-in] indicate that function pure and could be potentially optimized for
* high ordered functions and lambda calculus
*/
@pure
function action(type: string, payload: object): object {
return {
type,
...payload
};
}
ts
/* [built-in]
* Same hint for TCO like in Kotlin
*/
@tailrec
function findFixPoint(x = 1.0): number {
return Math.abs(x - Math.cos(x)) < eps ? x : findFixPoint(Math.cos(x));
}
Javascript world more and more shifted to functional paradigm and in this case functional level decorators is very necessary in my opinion)
Подсветку синтаксиса неплохо бы улучшить, а то декораторы совсем незаметны на скринах ниже и сливаются с комментариями
Anonymous
Denis
Syntax Highlight Bot
Lena Sheff
Dmitry
Roman
Dmitriy