Skip to content

Instantly share code, notes, and snippets.

@amasad
Last active August 29, 2015 14:05
Show Gist options
  • Save amasad/87890505b2ed1c51b353 to your computer and use it in GitHub Desktop.
Save amasad/87890505b2ed1c51b353 to your computer and use it in GitHub Desktop.

What about a closure in the param list that refers to a param later in the list?

function foo(bar = function() { return x; }, x = 1) {
  return bar();
}
foo(); // throws or 1?

I'm inclined to think that's fine because it's equivalent to:

{
  var bar = function() {
    return x;
  }
  let x = 1;
  bar();
}

But then I'm thinking the following should throw?

function foo(bar = function() { return x; }, x = bar()) {
  return x;
}
foo(); // throws or undefined?

Finally what about this:

function foo(bar = function(y = x) { return y; }, x = 1) {
  return bar();
}
foo(); // throws or is 1?

With regards to transpiling it seems like TDZ has to be a static check.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment