Pure functions in EcmaScript

Marius Gundersen gundersen at gmail.com
Wed Nov 28 03:50:16 PST 2012

Has there been any work done on pure functions in EcmaScript? The way I
imagine it, there would be a way to indicate that a function should be pure
(by using a symbol or a new keyword, although I understand new keywords
aren't terribly popular). The pure function is not allowed to access any
variable outside its own scope. Any access to a variable outside the scope
of the function would result in a Reference Error, with an indication that
the reference attempt was made from a pure function. This also applies to
any function called from within the pure function. The entire stack of a
pure function must be pure. This also means the pure function cannot access
the [this] object. Only the parameters  passed to the function can be used
in the calculation.

The syntax could be something like this (the @ indicates that it is pure):

function sum@(a, b){
  return a+b;

var sum = function@(a, b){
  return a+b;

Marius Gundersen
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.mozilla.org/pipermail/es-discuss/attachments/20121128/268f2bfb/attachment.html>

More information about the es-discuss mailing list