In Javascript, is it possible to proxy 'this' within a constructor, without editing the constructor

49 views Asked by At

Imagine I have the following Javascript class:

class C {
  constructor() {
    this.foo = "bar"
  }
}

I have proxied C so I can intercept construction of C:

const handler = {
  construct(target, args, newTarget) {
    ...
  }
}

I need to find a way to replace this in this.foo with a proxy. It must be done at the start of the constructor -- I cannot wait for the constructor to return and then proxy the result.

Does anyone have any suggestions on how to do this? Is it even possible?

0

There are 0 answers