Gitsunmin

TIL

TIL
(=Today I Learned)

Proxy Grammar

Proxy 객체를 사용하면 한 객체에 대한 기본 작업을 가로채고 재정의하는 프록시를 만들 수 있습니다.

const target = {
  message1: "hello",
  message2: "everyone"
};

const handler2 = {
  get(target, prop, receiver) {
    return "world";
  }
};

const proxy2 = new Proxy(target, handler2);

이렇게 작성하고, log를 찍어보면, 아래처럼 world, world가 나오는 것을 확인할 수 있다.

console.log(proxy2.message1, proxy2.message2); 
// world, world

proxy는 vaildation하거나, 값을 수정할 때 쓰일 수 있습니다.