title: In JS, how do I access a given property path of any given object?
body: <p>To make things more clear, here's an example. I tried to strip everything down to the bone and only keep the relevant details. Here's a dummy class <code>Person</code> with some properties and subproperties:</p>
  <pre><code>class Person {
    height = 100;
    hat = {size: 4};
  }
  </code></pre>
  <p>Now, I have some other class whose purpose is to modify some (sub)*property of <code>Person</code>:</p>
  <pre><code>class PersonModifier {
    constructor(propertyPath, value) {
      this.propertyPath = propertyPath; // this is the part I'm a bit lost on
      this.value = value; // a numeric value just to demonstrate how this class would work
    }
  
    actUpon(person) { // modifies a quantitative attribute of Person by a given amount
      person.(this.propertyPath) += value;
    }
  }
  </code></pre>
  <p>I'm aware the sole line of code inside the <code>actUpon</code> method doesn't work syntactically, I hope I got the point across as to what I'm trying to do. I guess it's similar to <code>Person.prototype.whatever</code> but I'd like to use it for attributes and not for methods.</p>
  <p>Here's an example of instance of the above class, whose purpose is to decrease one's hat size by 2:</p>
  <pre><code>let hatShrinker = new PersonModifier(.hat.size, -2);
  </code></pre>
  <p>Again, that obviously doesn't work syntactically, so here's my question:</p>
  <p>How do I store and use a property path (of arbitrary depth), such that I can access and write such properties of any object? Consider that I know what classes the object belongs to beforehand (in this example, <code>Person</code>).</p>
  <p><strong>Note:</strong> <em>any solution not involving strings would be preferred, as strings are not affected by some important IDE features like refactoring and suggestions based on dynamic type</em></p>