我正在尝试为格式函数添加功能,但我的代码有问题:
Object.defineProperty(Intl.NumberFormat.prototype, "format", { value: function(){
//your logic here
let orig = Intl.NumberFormat.prototype
console.log(orig);// does not remember the original proto
}, configurable: true } );
我错过了什么?
你基本上抓住了属性本身。您希望在覆盖之前获取原始对象,并且您也可以通过复制它们来存储其子对象引用:
{
let orig = Object.assign({}, Intl.NumberFormat.prototype);
Object.defineProperty(Intl.NumberFormat.prototype, "format", { value: function(){
//your logic here
console.log(orig);// does remember the original proto
}, configurable: true } );
}