You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I think the current definition of side effects is incorrect:
A function is considered to have side effects if it performs any action other than returning a value. Side effects include, but are not limited to, modifying variables or objects, reading or writing to files, making network requests, and interacting with the DOM.
I believe the above description suits pure more than side effects. A function can have no side effects even if it reads external data such as files or variables from outer scopes. On the other hand, it would cause side effects if the function wrote to a file or modified variable from outer scopes (note that modifying variables created in its own scope still doesn't count as having side effects).
Although, I understand that even reading a JS variable may cause a side effect in certain situations (for example, when using a proxy). Network requests, even GET requests, may cause side effects too (eg, a page view counter that increases for each visit). Finally, reading files may cause the OS to update some file descriptors or whatever... But still, is it safe to assume that most of the time, those operations shouldn't count as side effects?
The text was updated successfully, but these errors were encountered:
I guess maybe we could remove that section, as explaining side-effect is probably not in the scope if the spec? Otherwise, feel free to send PRs to rewrite them into what make send to you
AFAIK, to Terser and uglifyjs, the pure annotation also asserts that the function will not be throwing an error. When minifying, you shouldn't remove code that throws.
I think the current definition of
side effects
is incorrect:I believe the above description suits
pure
more thanside effects
. A function can have no side effects even if it reads external data such as files or variables from outer scopes. On the other hand, it would cause side effects if the function wrote to a file or modified variable from outer scopes (note that modifying variables created in its own scope still doesn't count as having side effects).Although, I understand that even reading a JS variable may cause a side effect in certain situations (for example, when using a proxy). Network requests, even GET requests, may cause side effects too (eg, a page view counter that increases for each visit). Finally, reading files may cause the OS to update some file descriptors or whatever... But still, is it safe to assume that most of the time, those operations shouldn't count as side effects?
The text was updated successfully, but these errors were encountered: