Expected function parameter scoping behavioor

Logan Smyth loganfsmyth at gmail.com
Tue May 9 19:40:00 UTC 2017

Hey all,
We're currently exploring some changes to Babel's behavior for function
parameter default scoping, and I was hoping to validate my understanding of
the spec, because my reading of the spec does not conform to Chrome or FF's
behavior. Alternatively if you know bugs for those engines for this, let me

My understanding from
https://tc39.github.io/ecma262/#sec-functiondeclarationinstantiation step
#27 is that if function parameters contain any expressions, the function
body is shifted to run in a declarative environment separately from the
params. Per #27.f.i.4.a, the initial values of the params are copied from
from the param environment into the function body environment, at initial
execution time.

Given that, I'd expect cases such as
(function fn(arg, setValue = function () { arg = "a string" }) {

  return arg;
to return `initial`, because the `arg` binding being mutated by `setValue`
is not tied to the `arg` binding that the function returns, as the
`"initial"` value would have been copied into the function body binding
before `setValue` ran.

Is my understanding there correct?

Similarly I'd have expected
(function fn(arg, getValue = function () { return arg; }) {

  arg = "new value";

  return getValue();

to return `"initial"` because it is returning the binding value from the
declarative environment in the function params and accessed by `getValue`
is not the same environment being mutated by the assignment to `arg1`.

Is my understanding correct, or is there something I'm misunderstanding?

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.mozilla.org/pipermail/es-discuss/attachments/20170509/5b08bff3/attachment.html>

More information about the es-discuss mailing list