object-properties
    Preparing search index...

    Function definePrototypeGetter

    • Defines a getter on a class prototype

      Type Parameters

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

      Parameters

      Returns any

      target

      class Rectangle {
      constructor(width, height) {
      this.width = width;
      this.height = height;
      }
      }
      definePrototypeGetter(Rectangle, 'area', function() {
      return this.width * this.height;
      });
      const rect = new Rectangle(5, 3);
      console.log(rect.area); // 15