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

Dependencies (1)

Dev Dependencies (2)

Package Sidebar

Install

npm i modify-property

Weekly Downloads

0

Version

1.0.0

License

MIT

Last publish

Collaborators

  • lamansky