title: Resolving a promise in a JavaScript Proxy object
body: <p>I am trying to create a JavaScript Proxy that allows me to deeply traverse an object's properties but when I run a method, I want it to return a promise with a new proxy that will let me deeply traverse that object.</p>
  <p>Example:</p>
  <pre><code>const foo = createProxy()
  const result = await foo.any.number.of.properties.deep()
  const result2 = await result.foo.bar()
  const result3 = await result2.off.we.go.again()
  </code></pre>
  <p>I have tried creating a proxy of a function and this works when I want to return a proxy synchronously from a method call, however when I try to return a promise it loops infinitely.</p>
  <p>However when I capture a <code>then</code> property and try to run the callback to pass the proxy to it, I break the browser with an infinite loop.</p>
  <pre><code>const createProxy = &lt;T&gt;(path) =&gt; {
    return new Proxy(function () {}, {
      apply(_target, _thisArg, _args) {
        console.log(&quot;exec&quot;, path);
        return createProxy([]);
      },
      get(_target, key) {
        if (key === &quot;then&quot;) {
          return (cb) =&gt; {
            cb(createProxy([...path, key]));
          };
        }
        return createProxy([...path, key]);
      },
    });
  };
  </code></pre>