object-properties
    Preparing search index...

    Function definePrototypeLazyProperty

    • Defines a lazy property on a class prototype

      Type Parameters

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

      Parameters

      • Class: T
      • property: P

        name of the property

      • callback: LazyCallback<V>

        function called when the property is accessed the first time

      • Optionaloptions: DefinePropertyOptions
        • Optionalconfigurable?: boolean
        • Optionalenumerable?: boolean
        • Optionalwritable?: boolean

      Returns any

      target

      class User {
      constructor(id) {
      this.id = id;
      }
      }
      definePrototypeLazyProperty(User, 'details', function() {
      return fetchUserDetails(this.id);
      });
      const user = new User(1);
      // details are fetched only when accessed
      console.log(user.details); // Fetches and returns user details