Identifying pure (or "pure within a scope") JavaScript functions?

Michael Haufe tno at thenewobjective.com
Thu Dec 7 17:35:33 UTC 2017


Relevant discussions:

<
https://groups.google.com/d/msg/mozilla.dev.tech.js-engine/aSKg4LujHuM/2Y9ORBwCIQAJ
>

and:

<
https://mail.mozilla.org/pipermail/es-discuss/2012-November/thread.html#26657
>


On Thu, Dec 7, 2017 at 11:15 AM, Michał Wadas <michalwadas at gmail.com> wrote:

> Only extremely small subset of functions can be proven to be pure. And I
> suppose that these functions are already optimized by engines.
>
> eg.
> notPure = (a,b) => a + b; // implicit conversion with side effects can
> happen
> notPure = (a) => a && a.b; // getter can be called
> notPure = (foo, bar) => Reflect.has(foo, bar); // proxy trap can be
> called. Someone could overwrite Reflect.has
>
> etc.
>
> It would be better idea to have builtin decorator *@pure* that allow
> engine to remove or reorganize function calls (and valid implementation can
> treat it as no-op).
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.mozilla.org/pipermail/es-discuss/attachments/20171207/10b72184/attachment.html>


More information about the es-discuss mailing list