3 ms·
I believe as well that the article is imprecise, since it elaborates on a trick question and tries to just inform about the term "pure" being hard to define, es
by philplckthun 10y ago
I believe as well that the article is imprecise, since it elaborates on a trick question and tries to just inform about the term "pure" being hard to define, especially in a dynamic language.
To be referencing an exact quote of the article to make it very clear:
var arr = [{}, {}, {}];
arr[0].valueOf = arr[1].valueOf = arr[2].valueOf = Math.random;
Obviously this relies on multiple function calls, so the output of the original function `sum` is still predictable. I think predictability and the absence of side effects is still a much better definition for pure functions.
It's also a necessary definition in JS. Saying that 'the same call of the function with similar enough arguments will always yield the same output' is not a sufficient definition and way too simplified.