프록시를 사용하여 동적 구성 불가능 속성을 만들고 싶습니다.프록시를 사용하여 동적 구성 할 수없는 속성 만들기
const proxy = new Proxy({}, {
getOwnPropertyDescriptor() {
return {
configurable: false,
enumerable: false,
};
},
});
console.log(Reflect.getOwnPropertyDescriptor(proxy, 'test'));
하지만 오류 받고 있어요 : :하지만 무엇을 설명하지 않습니다
A property cannot be reported as non-configurable, if it does not exists as an own property of the target object or if it exists as a configurable own property of the target object.
:
TypeError: 'getOwnPropertyDescriptor' on proxy: trap reported non-configurability for property 'test' which is either non-existant or configurable in the proxy target
MDN가 있다고 나는이 시도 이것 뒤에 이유.
이 오류에 대한 대안이 있습니까?
위대한 설명, 고마워. 내 해결책에 대해 어떻게 생각하니? 내가 생각하지 못한 부작용이 있습니까? –
@ 고토 예, 올바르게 작동합니다. 다른 프록시 나 확장 불가능한 객체와 같은 좀 더 일반적인 목표에 문제가있을 수 있지만'{}'를 사용하고 다른 코드에 노출시키지 않으면 문제가 발생하지 않습니다. – Oriol