I have a class as follows:
// A validator class for strings
class StringValidation {
type = "string";
max(maximum = 255) {
this.maximum = maximum;
return this;
}
min(minimum = 1) {
this.minimum = minimum;
return this;
}
}
// I then build the object
const string = new StringValidation();
// When I stringify the string objects after calling the object methods
// I get `{"type":"string","maximum":10,"minimum":5}`
console.log(JSON.stringify(string.max(10).min(5)));
// When I log the keys of the object
// I get `["type","maximum","minimum"]`
console.log(Object.keys(string.max(10).min(5)));
When I stringify the instance of class or print it's keys, I don't get max and min methods in the output.
This behaviour is quite confusing to me. Could anybody explain why did I get these results and why min & max methods seem to disappear.