object-properties
    Preparing search index...

    Function definePrototypeLazyConstant

    • Defines a lazy constant 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: EnumerableOptions
        • Optionalenumerable?: boolean

      Returns any

      target

      class Database {
      constructor(url) {
      this.url = url;
      }
      }
      definePrototypeLazyConstant(Database, 'connection', function() {
      return createDatabaseConnection(this.url);
      });
      const db = new Database('mongodb://localhost');
      // Connection is established only when first accessed
      console.log(db.connection);