Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Can a function be declared as pure at definition?

According to Webpack documentation:

It can be put in front of function calls to mark them as side-effect-free. Arguments passed to the function are not being marked by the annotation and may need to be marked individually.

Can we write PURE function at declaration ? Something like:

var max = /*#__PURE__*/(a,b) => { return (a>b)?a:b }

If yes, what is the right syntax?

like image 375
Alphonsio Avatar asked Mar 02 '26 04:03

Alphonsio


1 Answers

As far as I know, there is no native way you can declare function as pure in JavaScript.

TypeScript has a proposal to introduce pure keyword for functions and methods, but currently this is just a draft. You can read the whole thread, if you want here. The thread contains a comment with draft proposal description. When and whether at all this idea will be implemented is very hard to say.

like image 123
ReasonX7 Avatar answered Mar 04 '26 18:03

ReasonX7



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!