Baseline Widely available
handler.ownKeys()
ã¡ã½ããã¯ããªãã¸ã§ã¯ãã® [[OwnPropertyKeys]]
å
é¨ã¡ã½ããã«å¯¾ãããã©ããã§ãã Object.keys()
, Reflect.ownKeys()
ãªã©ã®æä½ã§ä½¿ç¨ããã¾ãã
const monster1 = {
_age: 111,
[Symbol("secret")]: "I am scared!",
eyeCount: 4,
};
const handler1 = {
ownKeys(target) {
return Reflect.ownKeys(target);
},
};
const proxy1 = new Proxy(monster1, handler1);
for (const key of Object.keys(proxy1)) {
console.log(key);
// Expected output: "_age"
// Expected output: "eyeCount"
}
æ§æ
new Proxy(target, {
ownKeys(target) {
}
});
弿°
次ã®å¼æ°ã¯ ownKeys()
ã¡ã½ããã«æ¸¡ããã¾ãã this
ã¯ãã³ãã©ã¼ã«ãã¤ã³ãããã¾ãã
target
ã¿ã¼ã²ãããªãã¸ã§ã¯ãã§ãã
ownKeys()
ã¡ã½ããã¯åæå¯è½ãªãã¸ã§ã¯ããè¿ããªããã°ãªãã¾ããã
ãã®ãã©ããã¯ä¸è¨ã®æä½ã«ä»å ¥ã§ãã¾ãã
ä»ã«ãã[[OwnPropertyKeys]]
å
é¨ã¡ã½ãããå¼ã³åºãããããæä½ã«ä»å
¥ã§ãã¾ãã
以ä¸ã®ä¸å¤æ¡ä»¶ã«éåãã¦ããå ´åããããã·ã¼ã¯ TypeError
ãçºçãã¾ãã
ownKeys()
ã®çµæã¯é
åã§ããå¿
è¦ãããã¾ããString
ã¾ã㯠Symbol
ã®ã©ã¡ããã§ããæ¬¡ã®ã³ã¼ãã§ã¯ Object.getOwnPropertyNames()
ããã©ãããã¾ãã
const p = new Proxy(
{},
{
ownKeys(target) {
console.log("called");
return ["a", "b", "c"];
},
},
);
console.log(Object.getOwnPropertyNames(p));
// "called"
// [ 'a', 'b', 'c' ]
次ã®ã³ã¼ãã§ã¯ä¸å¤æ¡ä»¶ã«éåãã¾ãã
const obj = {};
Object.defineProperty(obj, "a", {
configurable: false,
enumerable: true,
value: 10,
});
const p = new Proxy(obj, {
ownKeys(target) {
return [123, 12.5, true, false, undefined, null, {}, []];
},
});
console.log(Object.getOwnPropertyNames(p));
// TypeError: proxy [[OwnPropertyKeys]] must return an array
// with only string and symbol elements
仿§æ¸ ãã©ã¦ã¶ã¼ã®äºææ§ é¢é£æ
å ±
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