modify-property

v1.0.0
For patching a property descriptor, including replacing getters/setters.
replace object property getter setter method descriptor

modify-property

A Node.js module which lets you patch the descriptor of an existing object property. This is primarily useful for swapping out getters or setters.

Installation

npm install modify-property --save

Usage

const obj = {}
Object.defineProperty(obj, 'name', {
  configurable: true, // <- Won't work if this isn't true
  enumerable: true,
  get () { return 'Bill' },
})

// Now we want to modify this property.

const modifyProperty = require('modify-property')

modifyProperty(obj, 'name', prop => { prop.get = () => 'Ben' })

obj.name // Ben
npm i modify-property

Metadata

  • MIT
  • >=4.0.0
  • John Lamansky
  • released 1/23/2017

Downloads

Maintainers