1. 程式人生 > >Ask HN: Should an arrow function be used as a pure function?

Ask HN: Should an arrow function be used as a pure function?

Do you consider an arrow function to have side effects since they don't have their own 'this'?

"In computer programming, a pure function is a function that has the following properties: - Its return value is the same for the same arguments (no variation with local static variables, non-local variables, mutable reference arguments or input streams from I/O devices). - Its evaluation has no side effects (no mutation of local static variables, non-local variables, mutable reference arguments or I/O streams)." [1]

"An arrow function does not have its own this; the this value of the enclosing lexical context is used i.e. Arrow functions follow the normal variable lookup rules. So while searching for this which is not present in current scope they end up finding this from its enclosing scope." [2]

[1] https://en.wikipedia.org/wiki/Pure_function [2] https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Functions/Arrow_functions