Miss any of our Open RFC calls?Watch the recordings here! »

modify-property

1.0.0 • Public • Published

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

Install

npm i modify-property

DownloadsWeekly Downloads

1

Version

1.0.0

License

MIT

Last publish

Collaborators

  • avatar