The following code traps the new
operator.
const p = new Proxy(function () {}, {
construct(target, argumentsList, newTarget) {
console.log(`called: ${argumentsList}`);
return { value: argumentsList[0] * 10 };
},
});
console.log(new p(1).value);
The following code violates the invariant.
const p = new Proxy(function () {}, {
construct(target, argumentsList, newTarget) {
return 1;
},
});
new p();
The following code improperly initializes the proxy. The target
in Proxy initialization must itself be a valid constructor for the new
operator.
const p = new Proxy(
{},
{
construct(target, argumentsList, newTarget) {
return {};
},
},
);
new p();