Baseline Widely available
handler.has()
ã¯ããªãã¸ã§ã¯ãã® [[HasProperty]]
å
é¨ã¡ã½ããã«å¯¾ãããã©ããã§ãã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
åå¨ã確èªããããããã£åã§ãã
has
ã¡ã½ããã¯è«çå¤ãè¿ããªããã°ãªãã¾ããã
ãã®ãã©ããã¯ä¸è¨ã®æä½ã«ä»å ¥ã§ãã¾ãã
in
æ¼ç®å: foo in proxy
with
ãã§ãã¯: with(proxy) { (foo); }
Reflect.has()
ä»ã«ãã[[HasProperty]]
å
é¨ã¡ã½ãããå¼ã³åºãããããæä½ã«ä»å
¥ã§ãã¾ãã
以ä¸ã®ä¸å¤æ¡ä»¶ã«éåãã¦ããå ´åããããã·ã¼ã¯ 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