| [ Web Proxy ] |
| Viewing: https://developer.mozilla.org/ko/docs/Web/JavaScript/Reference/Global_Objects/Proxy/Proxy/ownKeys | [Back] [Original] |
Get to know MDN better
This page was translated from English by the community. Learn more and join the MDN Web Docs community.
This feature is well established and works across many devices and browser versions. Its been available across browsers since 2016 9.
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 .
ownKeys() .
handler.ownKeys() Reflect.ownKeys() .
.
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
| Specification |
|---|
| ECMAScript 2027 LanguageSpecification # sec-proxy-object-internal-methods-and-internal-slots-ownpropertykeys |
This page was last modified on 2025 2 11 by MDN contributors.
Your blueprint for a better internet.
Portions of this content are 19982026 by individual mozilla.org contributors. Content available under a Creative Commons license.
| Web Proxy Viewer | New URL | Original Page |