/**
* Proxy — an object standing where another would, deciding what to pass on.
*/
const engine = {
start(): string {
return "running";
},
secretKey: "hunter2",
};
// The language provides the pattern. This proxy was never told what shape
// `engine` is, and will not need telling when that shape changes.
const guarded = new Proxy(engine, {
get(target, property, receiver) {
if (property === "secretKey") {
throw new Error("not yours");
}
return Reflect.get(target, property, receiver);
},
});