I have been trying to find a way to have class parameter that can be formatted.
class Animal {
this.dob: '2019-12-12';
// Pseudo code
format: (date, format) => formatDate(date, format);
}
const animal = new Animal();
when calling it: animal.dob
I want to see '2019-12-12'
but if I want it formatted, I'd like to have the option to chain:
animal.dob.format('DD.MM)
which would return '12-12'
My main reason for doing that is that at the moment I have format(animal.dob, 'DD.MM')
littering my code all over the place and I would like to remove these calls as much as possible.
Any idea on how to achieve that?
Thanks in advance