👍:0
- If you want to inherit a new custom method to the instances of an object, you need to define them in the prototype, so instead of
Date.formatMMDDYYYY = () => {...}
use thisDate.prototype.formatMMDDYYYY = function{...}
, we can’t use arrow functions because then we won’t get the right values forthis
. Also you could have used instead a normal function that received a Date and call it whenever you need it, this way was more easy and safe. - Small error about the order in the format string the method is returning, instead of
this.getDate() + 1 + "/" + this.getMonth() +...
it should bethis.getMonth() + 1 + "/" + this.getDate() +...
- You are trying to get the data from
results
, but data is not there it’s inresults.data
, so the cycle should beresults.data.forEach(packet => {...}
Fixed code here: https://codesandbox.io/s/p3q2pz2l8x