name of the property
value
Optional
options: EnumerableOptionsOptional
enumerable?: booleantarget
class ValidationRule {
constructor(value) {
this.value = value;
}
validate() {
return this.value <= this.MAX_LENGTH && this.value >= this.MIN_LENGTH;
}
}
definePrototypeConstant(ValidationRule, 'MIN_LENGTH', 3);
definePrototypeConstant(ValidationRule, 'MAX_LENGTH', 50);
const rule = new ValidationRule('hello');
console.log(rule.MIN_LENGTH); // 3
rule.MIN_LENGTH = 1; // Will not change the value
Defines a constant property on a class prototype