Baseline Widely available
éç㪠Reflect.has()
ã¡ã½ããã¯ãæ©è½ã¨ãã¦ã¯ in
æ¼ç®åã®ããã«åä½ãã¾ãã
const object1 = {
property1: 42,
};
console.log(Reflect.has(object1, "property1"));
// Expected output: true
console.log(Reflect.has(object1, "property2"));
// Expected output: false
console.log(Reflect.has(object1, "toString"));
// Expected output: true
æ§æ
Reflect.has(target, propertyKey)弿°
target
ããããã£ãæ¢ã対象ã®ãªãã¸ã§ã¯ãã
propertyKey
ãã§ãã¯ããããããã£åã
対象ãããããã£ãæã¤ãã©ããã示ã Boolean
å¤ã
target
ã Object
ã§ãªãã£ãå ´åã TypeError
ãçºçãã¾ãã
Reflect.has
ã¡ã½ããã¯ããªãã¸ã§ã¯ãããããã£ããããããã§ãã¯ãã¾ããæ©è½ã¨ãã¦ã¯ in
æ¼ç®åã®ããã«åä½ãã¾ãã
Reflect.has({ x: 0 }, "x"); // true
Reflect.has({ x: 0 }, "y"); // false
// ãããã¿ã¤ããã§ã¼ã³ã®ããããã£ããããããtrue ãè¿ã
Reflect.has({ x: 0 }, "toString");
// Proxy with .has() handler method
obj = new Proxy(
{},
{
has(t, k) {
return k.startsWith("door");
},
},
);
Reflect.has(obj, "doorbell"); // true
Reflect.has(obj, "dormitory"); // false
Reflect.has
ã¯ç¶æ¿ãããããããã£ã«ã¤ã㦠true
ãè¿ãããã㯠in
æ¼ç®åã¨åæ§ã§ãã
const a = { foo: 123 };
const b = { __proto__: a };
const c = { __proto__: b };
// The prototype chain is: c -> b -> a
Reflect.has(c, "foo"); // true
仿§æ¸ ãã©ã¦ã¶ã¼ã®äºææ§ é¢é£æ
å ±
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