Can a function be declared as pure at definition?

83 views Asked by At

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?

1

There are 1 answers

0
Bogdan Gishka On

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.