Baseline Widely available
éç㪠Reflect.get()
ã¡ã½ããã¯ããªãã¸ã§ã¯ã (target[propertyKey]
) ããããããã£ã颿°ã¨ãã¦åå¾ããããã«åä½ãã¾ãã
const object1 = {
x: 1,
y: 2,
};
console.log(Reflect.get(object1, "x"));
// Expected output: 1
const array1 = ["zero", "one"];
console.log(Reflect.get(array1, 1));
// Expected output: "one"
æ§æ
Reflect.get(target, propertyKey[, receiver])
弿°
target
ããããã£ãåå¾ãã対象ã®ãªãã¸ã§ã¯ãã
propertyKey
è¨å®ããããããã£åã
receiver
çç¥å¯
ã²ãã¿ã¼ããã£ãå ´åã target
ã¸ã®å¼ã³åºãã§ä½¿ç¨ãã this
ã®å¤ãæä¾ãã¾ãã Proxy
ã¨ã¨ãã«ä½¿ç¨ããã¨ã target
ããç¶æ¿ãã¦ãããªãã¸ã§ã¯ãã«ãããã¨ãã§ãã¾ãã
ããããã£ã®å¤ã§ãã
ä¾å¤target
ã Object
ã§ãªãã£ãå ´åã TypeError
ãçºçãã¾ãã
Reflect.get
ã¡ã½ããã¯ãªãã¸ã§ã¯ãã®ããããã£ãåå¾ãã¾ããæ©è½ã¨ãã¦ã¯ããããã£ã¢ã¯ã»ãµã¼æ§æã¨ä¼¼ã¦ãã¾ãã
Reflect.get()
ã®ä½¿ç¨
// ãªãã¸ã§ã¯ã
let obj = { x: 1, y: 2 };
Reflect.get(obj, "x"); // 1
// é
å
Reflect.get(["zero", "one"], 1); // "one"
// Proxy with a get handler
let x = { p: 1 };
let obj = new Proxy(x, {
get(t, k, r) {
return k + "bar";
},
});
Reflect.get(obj, "foo"); // "foobar"
//Proxy with get handler and receiver
let x = { p: 1, foo: 2 };
let y = { foo: 3 };
let obj = new Proxy(x, {
get(t, prop, receiver) {
return receiver[prop] + "bar";
},
});
Reflect.get(obj, "foo", y); // "3bar"
仿§æ¸ ãã©ã¦ã¶ã¼ã®äºææ§ é¢é£æ
å ±
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