Baseline Widely available
handler.has()
ë©ìëë in
ì°ì°ìì ëí í¸ë©ì
ëë¤.
const handler1 = {
has(target, key) {
if (key[0] === "_") {
return false;
}
return key in target;
},
};
const monster1 = {
_secret: "easily scared",
eyeCount: 4,
};
const proxy1 = new Proxy(monster1, handler1);
console.log("eyeCount" in proxy1);
// Expected output: true
console.log("_secret" in proxy1);
// Expected output: false
console.log("_secret" in monster1);
// Expected output: true
구문
new Proxy(target, {
has(target, prop) {},
});
ë§¤ê° ë³ì
ë¤ì 매ê°ë³ìë has()
ë©ìëì ì ë¬ë©ëë¤. this
ë ì²ë¦¬ê¸°ì ë°ì¸ë©ë©ëë¤.
target
ëì ê°ì²´
prop
ì¡´ì¬ ì¬ë¶ë¥¼ íì¸í ìì±ì ì´ë¦ ëë Symbol
has()
ë©ìëë ë¶ë¦¬ì¸ ê°ì ë°íí©ëë¤.
handler.has()
ë©ìëë in
ì°ì°ìì ëí í¸ë©ì
ëë¤.
ì´ í¸ë©ì ë¤ì ìì ì ê°ë¡ì± ì ììµëë¤.
foo in proxy
foo in Object.create(proxy)
with
íì¸: with(proxy) { (foo); }
Reflect.has()
ë¤ì ë¶ë³ ì¡°ê±´ì´ ìë°ëë©´ íë¡ììì TypeError
ê° ë°ìí©ëë¤.
ë¤ì ì½ëë in
ì°ì°ì를 í¸ë©í©ëë¤.
const p = new Proxy(
{},
{
has(target, prop) {
console.log(`called: ${prop}`);
return true;
},
},
);
console.log("a" in p); // "called: a"
// true
ë¤ì ì½ëë ë¶ë³ ì¡°ê±´ì ìë°í©ëë¤.
const obj = { a: 10 };
Object.preventExtensions(obj);
const p = new Proxy(obj, {
has(target, prop) {
return false;
},
});
"a" in p; // 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