2

我正在尝试向格式函数添加功能,但我的代码有问题:

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 } );

我错过了什么?

4

1 回答 1

1

你基本上抓住了财产本身。你想在它被覆盖之前得到原始的,你也可以通过复制它们来存储它的子对象引用:

{
   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 } );
}
于 2017-07-03T09:33:24.997 回答