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?
2
Answers
As far as I know, there is no 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 proposal. 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 Bogdan Gishka noted, there is no (formal) way to declare a function as pure. Maybe it’s an idea to use a
Symbol
for it?