object-properties
    Preparing search index...

    Function defineProperty

    • Defines a property on an object with optional configuration

      Type Parameters

      • T
      • P extends string
      • V

      Parameters

      • target: T
      • property: P

        name of the property

      • value: V

        value

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

      Returns any

      target

      const obj = {};
      defineProperty(obj, 'name', 'John');
      console.log(obj.name); // 'John'

      // With options
      defineProperty(obj, 'age', 25, { writable: false });
      obj.age = 30; // Will not change the value
      console.log(obj.age); // 25