title: ES6 getter setter with JSON object
body: <p>According to this doc</p>
  
  <p><a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Functions/set" rel="nofollow">https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Functions/set</a></p>
  
  <p>You can do something like this</p>
  
  <pre><code>var o = {
    set current (str) {
      this.log[this.log.length] = str;
    },
    log: []
  }
  </code></pre>
  
  <p>But what if I want the <code>current</code> variable to be object and I want to do <code>setter</code> on a property of that object?</p>
  
  <p>The below doesn't seem to work</p>
  
  <pre><code>var o = {
    set current.myVal (str) {
      this.log[this.log.length] = str;
    },
    log: []
  }
  </code></pre>
  
  <p>What is the correct way to do this? I read that you can use <code>expression</code> but there is no example.</p>
  
  <p>** UPDATE 1 **</p>
  
  <p>One of the answers below is correct but what if it's <code>class</code>?</p>
  
  <pre><code>class o {
    set current.myVal (str) {
      this.log[this.log.length] = str;
    }
  }
  </code></pre>
  
  <p>I tried below and didn't work</p>
  
  <pre><code>class o {
    current: {
      set myVal(str) {
        o.log.push(str);
      }
    }
  }
  </code></pre>