var funcSetter = {
defineProperty: function(target, prop, descriptor) {
if (prop) {
let temp = descriptor.value;
descriptor.value = temp => {
if (temp.startsWith('_')) {
temp = "Default Value Attached , no Underscores allowed";
return temp;
} else return temp;
};
}
return true;
}
};
let proxy_3 = new Proxy(obj_3, funcSetter);
Object.defineProperty(proxy_3, 'no', {
value: '_Bharath',
writable: true,
enumerable: true,
configurable: true
});
我這裏面臨的問題是,當我打電話陷阱defineProperty
,descriptor.value
下定義的箭頭功能不被調用,點擊底部的迴歸真實,並設置爲undefined
爲什麼我從defineProperty方法中得到一個未定義的值?
我很確定我沒有正確使用箭頭功能。任何人都可以引導我走向正確的方向嗎?
謝謝你的所有提示。非常感激!
請添加一些用例。 –
這是一些東西,我在JS中學習代理和反思時正在進行試驗。本身沒有用例。 – Bharath
* defineProperty方法必須返回一個布爾值,指示該屬性是否已被成功定義* - https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Proxy/handler/defineProperty #Return_value –