Static & Private Class Fields
What advantages does this private static implementation provide?
class Validator {
static #rules = new Map();
static {
this.#rules.set('email', /^[^@]+@[^@]+\.[^@]+$/);
this.#rules.set('phone', /^\d{10}$/);
}
static validate(type, value) {
const rule = this.#rules.get(type);
return rule?.test(value) ?? false;
}
}