Parameter lists as arguments destructuring sugar

Sean Eagan seaneagan1 at gmail.com
Wed Apr 6 11:33:31 PDT 2011


Also, as destructuring / rest parameters / "this = defaultThis|"
already allows things like...

  function (this = defaultThis| [a, {b}], ...c ){}

... it would probably be useful to allow equivalent functions to be
declared dynamically with "new Function", something like ...

  let f = new Function(
    "this = defaultThis| [a, {b}], ...c",
    ""
  );

As mentioned above, the main opportunity here is feature parity
between parameter lists and array destructuring, the sugar part would
just be a bonus.  Just to improve the clarity of the desugaring
though, here are some improvements...

* don't desguar to "function f() ..." as that would cause infinitely
recursive desugaring, instead use the dynamic function declaration
extension proposed above
* to think from a functional POV, |__this__| could instead just be the
first element of |__arguments__|.
* |this| is normally unassignable (I couldn't actually find this
requirement in the ES5 spec though, probably just overlooking it), so
it should really be setting the function execution context's
ThisBinding, which could be represented as __ThisBinding__
* avoid overriding an explicit |undefined| ThisBinding from ES5
section 10.4.3 step 1 by checking ThisBinding explicitness represented
as the boolean __ThisBindingIsExplicit__


function f (this = defaultThis|a, , c = "c", ...d) {
 //...
}

... would then desugar to ...

let __parameterList__ = "a, , c = \"c\", ...d";
var f = new Function(
  __parameterList__,
  "  var [__ThisBinding__ = (__ThisBindingIsExplicit__ ?
__ThisBinding__ : defaultThis), " + __parameterList__] =
__arguments__;  //..."
);


Cheers,
Sean Eagan


More information about the es-discuss mailing list