1

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?

Bergi
  • 630,263
  • 148
  • 957
  • 1,375
Roni Gadot
  • 437
  • 2
  • 19
  • 30

1 Answers1

1

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 } );
}
Jonas Wilms
  • 132,000
  • 20
  • 149
  • 151