object-properties
    Preparing search index...

    Function definePrototypeSetter

    • Defines a setter on a class prototype

      Type Parameters

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

      Parameters

      Returns any

      target

      class Circle {
      constructor() {
      this._radius = 0;
      }
      }
      definePrototypeSetter(Circle, 'radius', function(value) {
      if (value < 0) throw new Error('Radius cannot be negative');
      this._radius = value;
      });
      const circle = new Circle();
      circle.radius = 5; // Sets _radius to 5