Reflect.get receiver Preserves Proxy Getters

Forward the third receiver argument in Reflect.get inside Proxy traps so inherited getters resolve this through the proxy rather than the raw target.

JavascriptConfig Management

Code

snippet
const baseConfig = {
  env: 'dev',
  service: 'billing',
  get endpointLabel() {
    // Depends on `this.env`, so the `this` binding during lookup matters
    return `${this.env}:${this.service}`;
  },
};

const envOverride = Object.create(baseConfig);
envOverride.env = 'staging';

// Buggy proxy omits `receiver`, so `target[prop]` binds `this` to `target` ('staging')
const brokenProxy = new Proxy(envOverride, {
  get(target, prop) {
    if (prop === 'env') return 'prod-override';
    return target[prop];
  },
});

// Correct proxy forwards `receiver`, so inherited getters see the proxy's `env`
const fixedProxy = new Proxy(envOverride, {
  get(target, prop, receiver) {
    if (prop === 'env') return 'prod-override';
    return Reflect.get(target, prop, receiver);
  },
});

console.log('broken env   :', brokenProxy.env);
console.log('broken label :', brokenProxy.endpointLabel);
console.log('fixed env    :', fixedProxy.env);
console.log('fixed label  :', fixedProxy.endpointLabel);

Output

Captured from a sandboxed run of this snippet in the build pipeline.

broken env   : prod-override
broken label : staging:billing
fixed env    : prod-override
fixed label  : prod-override:billing

Code flow overview — Reflect.get receiver Preserves Proxy Getters

Top-level bindings baseConfig, envOverride, brokenProxy, fixedProxy hold the demo state — nothing sits inside a function scope.

Watch out for

  • All referenced identifiers stay native to the language runtime — zero remote packages fetched.
  • The guard prop === 'env' bails cleanly ahead of remaining work via an early return when its condition holds.

Using it

The run prints broken env :, broken label :, fixed env : — each prefix names the step that produced it.

Key statements

if (prop === 'env') return 'prod-override';
return Reflect.get(target, prop, receiver);
return `${this.env}:${this.service}`;

Interactive Tools for This Topic

FAQ

Will the snippet run without installing packages?
Yes, it runs as-is — nothing outside the built-in APIs is referenced. Its state lives in module-level bindings: `baseConfig`, `envOverride`, `brokenProxy`.