Hi,

I think it could be quite useful to spec parameter lists as mere
arguments destructuring sugar, something like this...

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

...could desugar to...

function f () {
  const this = __this__ ?? defaultThis;
  var [a, , c = "c", ...d] = __arguments__;
  //...
}

Notes:

* |__arguments__| is an inaccessible construct (as seen in many other
desugaring examples) similar to |arguments|.  Didn't use |arguments|
since sharp (and eventually all) functions want to deprecate it.

* "this = defaultThis|" is a stand in for whatever is decided as to
the discussion in [1].

* |__this__| represents any explicit this binding via call, apply,
bind, softBind etc. or undefined if there is no explicit binding;

* |??| is the default operator [2].  I think at least in strict mode
this is not quite correct since it is possible to explicitly set
|this| to |undefined|.

* Parameter lists would still be used to set a function's internal
[[FormalParameters]] property, which might be avoidable however for
sharp functions since they do not have |arguments|



This could simplify the spec in regard to parameter lists, and would
remove the need to normatively spec rest parameters altogether.  More
importantly, it would bring feature parity between parameter lists and
array destructuring, thus allowing for:

* Default values in array destructuring patterns

  [x, y, z = "z"] = arr;

* Omission of identifiers for non-important parameters in callback functions

  function callback (x, , z) {
    return foo(x, z);
  }


Also, just regarding parameter lists and destructuring in general,
here are some additional potentially useful features:

* Don't require parameters with default values to occur at the end of
the parameter lists since all parameters already have an implicit
default value of |undefined|

  function(x = 5, y){}

  ... could be considered equivalent to...

  function(x = 5, y = undefined){}

* Overriding var, let, const bindings (is this already allowed?
couldn't tell from [3])

  let [a, const b, var {x, let "y": z}] = arr;

* Early spread operator, see [4].

[1] https://mail.mozilla.org/pipermail/es-discuss/2011-March/013437.html
[2] http://wiki.ecmascript.org/doku.php?id=strawman:default_operator
[3] http://wiki.ecmascript.org/doku.php?id=harmony:destructuring
[4] https://mail.mozilla.org/pipermail/es-discuss/2011-April/013528.html

Cheers,
Sean Eagan
_______________________________________________
es-discuss mailing list
es-discuss@mozilla.org
https://mail.mozilla.org/listinfo/es-discuss

Reply via email to