object-properties
    Preparing search index...

    Function defineLazyConstant

    • Defines a constant property that is initialized only when first accessed

      Type Parameters

      • T
      • P extends string
      • V

      Parameters

      • target: 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

      const obj = {};
      defineLazyConstant(obj, 'config', function() {
      return loadConfigurationFile();
      });
      // config is loaded only when first accessed
      console.log(obj.config); // Loads and returns the config
      obj.config = {}; // Will not change the value