I'm finding different implementations to hook all instances of a class to a proxy.
Inside the class constructor (example):
class Foo {
constructor(...args) {
//...
return new Proxy(this, {
//...
});
}
}
With the construct handler (example):
class Foo {
constructor(...args) {
//...
}
}
new Proxy(Foo, {
construct(Foo, args, newTarget) {
// ...
return Reflect.construct(Foo, [...args], newTarget);
},
//...
});
Is there a difference in these implementations? I want to make a generic setter and getter; so in the second alternative I would have to create a proxy inside the proxy, which in terms of memory allocation and performance would be the same I think.
Is it so?