Adding functionality to Intl.NumberFormat

138 Views Asked by At

I'm trying to add functionality to the format function but there is something wrong with my code:

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

What am I missing?

1

There are 1 best solutions below

2
Jonas Wilms On BEST ANSWER

You basically catch the property itself. You want to get the original one so before it is overriden, and you may store its subobject references too through copying them:

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