[ Web Proxy ]
URL:
Viewing: https://developer.mozilla.org/ko/docs/Web/JavaScript/Reference/Global_Objects/Proxy/Proxy/get [Back]  [Original]

handler.get() - JavaScript | MDN

This page was translated from English by the community. Learn more and join the MDN Web Docs community.

View in English Always switch to English

handler.get()

Baseline Widely available

This feature is well established and works across many devices and browser versions. Its been available across browsers since 2016 9.

handler.get() .

In this article

const monster1 = {
  secret: "easily scared",
  eyeCount: 4,
};

const handler1 = {
  get: function (target, prop, receiver) {
    if (prop === "secret") {
      return `${target.secret.substring(0, 4)} ... shhhh!`;
    }
    return Reflect.get(...arguments);
  },
};

const proxy1 = new Proxy(monster1, handler1);

console.log(proxy1.eyeCount);
// Expected output: 4

console.log(proxy1.secret);
// Expected output: "easi ... shhhh!"

js
new Proxy(target, {
  get(target, property, receiver) {},
});

get() . this .

target

property

Symbol.

receiver

.

get() .

handler.get() .

.

  • : proxy[foo] proxy.bar
  • : Object.create(proxy)[foo]
  • Reflect.get()

TypeError .

  • , .
  • [[Get]] undefined , .

.

js
const p = new Proxy(
  {},
  {
    get(target, property, receiver) {
      console.log(`called: ${property}`);
      return 10;
    },
  },
);

console.log(p.a); // "called: a"
// 10

.

js
const obj = {};
Object.defineProperty(obj, "a", {
  configurable: false,
  enumerable: false,
  value: 10,
  writable: false,
});

const p = new Proxy(obj, {
  get(target, property) {
    return 20;
  },
});

p.a; // TypeError is thrown

Specification
ECMAScript 2027 LanguageSpecification
# sec-proxy-object-internal-methods-and-internal-slots-get-p-receiver


Web Proxy Viewer  |  New URL  |  Original Page