title: How does `this` work in default parameters?
body: <p>So... ES6¹ (which happens to be standardized a few hours ago) brings <em>default parameters</em> for functions similar to those in PHP, Python etc. I can do stuff like:</p>
  
  <pre><code>function foo (bar = 'dum') {
      return bar;
  }
  
  foo(1); // 1
  foo(); // 'dum'
  foo(undefined); // 'dum'
  </code></pre>
  
  <p>MDN says that the default value for the parameter is evaluated at call time. Which means each time I call the function, the expression <code>'dum'</code> is evaluated again (unless the implementation does some weird optimizations which we don't care about).</p>
  
  <p>My question is, how does <code>this</code> play into this?</p>
  
  <pre><code>let x = {
    foo (bar = this.foo) {
      return bar;
    }
  }
  
  let y = {
    z: x.foo
  }
  
  x.foo() === y.z(); // what?
  </code></pre>
  
  <p>The babel transpiler currently evaluates² it as <code>false</code>, but I don't get it. If they are really evaluated at call time, what about this:</p>
  
  <pre><code>let x = 'x from global';
  
  function bar (thing = x) {
    return thing;
  }
  
  function foo () {
    let x = 'x from foo';
    return bar();
  }
  
  bar() === foo(); // what?
  </code></pre>
  
  <p>The babel transpiler currently evaluates³ it as <code>true</code>, but I don't get it. Why does <code>bar</code> not take the <code>x</code> from <code>foo</code> when called inside <code>foo</code>?</p>
  
  <p><sub>
  1 - Yes I know it is ES2015.<br>
  2 - <a href="https://babeljs.io/repl/#?experimental=true&amp;evaluate=true&amp;loose=false&amp;spec=true&amp;playground=true&amp;code=let%20x%20%3D%20%7B%0A%20%20foo%20(bar%20%3D%20this.foo)%20%7B%0A%20%20%20%20return%20bar%3B%0A%20%20%7D%0A%7D%0A%0Alet%20y%20%3D%20%7B%0A%20%20z%3A%20x.foo%0A%7D%0A%0Aconsole.log(x.foo()%20%3D%3D%3D%20y.z())" rel="nofollow noreferrer">Example A</a><br>
  3 - <a href="https://babeljs.io/repl/#?experimental=true&amp;evaluate=true&amp;loose=false&amp;spec=true&amp;playground=true&amp;code=let%20x%20%3D%20&#39;x%20from%20global&#39;%3B%0A%0Afunction%20bar%20(thing%20%3D%20x)%20%7B%0A%20%20return%20thing%3B%0A%7D%0A%0Afunction%20foo%20()%20%7B%0A%20%20let%20x%20%3D%20&#39;x%20from%20foo&#39;%3B%0A%20%20return%20bar()%3B%0A%7D%0A%0Aconsole.log(bar()%20%3D%3D%3D%20foo())%3B" rel="nofollow noreferrer">Example B</a></p>
  
  <p></sub></p>