object-properties
    Preparing search index...

    Function definePrototypeConstant

    • Defines a constant property on a class prototype

      Type Parameters

      • T extends { prototype: unknown }
      • P extends string
      • V

      Parameters

      • Class: T
      • property: P

        name of the property

      • value: V

        value

      • Optionaloptions: EnumerableOptions
        • Optionalenumerable?: boolean

      Returns any

      target

      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