Continuing woes in reading the ES6 spec language

Andreas Rossberg rossberg at
Fri Sep 13 12:27:26 PDT 2013

On 13 September 2013 20:17, Oliver Hunt <oliver at> wrote:
> Introducing a new scope for each argument could be extraordinarily
> expensive, also would make some semantics weird:
> function f(a=1, b=function(){return a}) {
> var a = 2;
> return b() // What's this?
> }

The semantics we tentatively agreed upon at the November meeting would
make this return 1 either way, since it would be roughly equivalent to

  function f(a1, b1) {
    let a = (a1 !== undefined) ? a1 : 1
    let b = (b1 !== undefined) ? b1 : function(){return a}
    return function(a, b){
      var a = 2
      return b()
    }.call(this, a, b)

That is, default arguments are evaluated is if you had written a
wrapper function that computes them. Note that this answer is
independent of the relative scoping of parameters.

We have discussed various semantics, and weird examples with closures,
and IIRC eventually came to the conclusion that closures in default
arguments are pretty much a lost cause, since any semantics will have
pathological cases given some of the ES5 rules we have to be
backwards-compatible with.

> if we say sequential scoping it becomes inconsistent for b to return 1, but
> the parameter shadowing of var means that it should.

I'm not following you here. Did you mean 2 instead of 1?


More information about the es-discuss mailing list