Baseline Widely available
handler.ownKeys()
ë©ìëë 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()
ë©ìëë ì´ê±° ê°ë¥í ê°ì²´ë¥¼ ë°íí©ëë¤.
handler.ownKeys()
ë©ìëë Reflect.ownKeys()
ì ëí í¸ë©ì
ëë¤.
ë¤ì ë¶ë³ ì¡°ê±´ì´ ìë°ëë©´ íë¡ììì 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