title: How to capture parent class 'this' in a child object getter in ES6 or later?
body: <p>Here is a simple JavaScript code:</p>
  
  <pre><code>class Test {
    constructor(val) {
      this._value = val;
      this.child = {
        get value() { return this._value; },
        getValue: () =&gt; { return this._value; }
      };
    }
  }
  
  let o = new Test(1);
  console.log(o.child.value);
  console.log(o.child.getValue());
  </code></pre>
  
  <p>The output:</p>
  
  <pre><code>undefined
  1
  </code></pre>
  
  <p>In the child object <code>child</code>, I want to make the getter <code>get value()</code> to produce the same value as the lambda <code>getValue()</code>, i.e. to capture the parent's <code>this</code> properly and produce <code>1</code> rather than <code>undefined</code>.</p>
  
  <p>Is there an elegant way of doing it within the <code>class</code>? Or should I use the lambda and give up on the getter?</p>
  
  <p>I could probably do this:</p>
  
  <pre><code>    this.child = {
        parent: this, 
        get value() { return this.parent._value; },
      };
  </code></pre>
  
  <p>However I don't want to expose <code>child.parent</code>, only <code>child.value</code>.</p>