Baseline Widely available
handler.get()
ë©ìëë ìì± ê°ì ê°ì ¸ì¤ê¸° ìí í¸ë©ì
ëë¤.
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!"
구문
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
ì¸ êµ¬ì±í ì ìë ìì²´ ì ê·¼ì ìì±ì¸ ê²½ì°, ìì±ì ëí´ ë³´ê³ ë ê°ì ì ìëì§ ììì¼ í©ëë¤.ë¤ì ì½ëë ìì± ê°ì ê°ì ¸ì¤ë ê²ì í¸ë©í©ëë¤.
const p = new Proxy(
{},
{
get(target, property, receiver) {
console.log(`called: ${property}`);
return 10;
},
},
);
console.log(p.a); // "called: a"
// 10
ë¤ì ì½ëë ë¶ë³ ì¡°ê±´ì ìë°í©ëë¤.
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
ëª
ì¸ì ë¸ë¼ì°ì í¸íì± ê°ì´ 보기
RetroSearch is an open source project built by @garambo | Open a GitHub Issue
Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo
HTML:
3.2
| Encoding:
UTF-8
| Version:
0.7.4