modify-property
v1.0.0
Published
For patching a property descriptor, including replacing getters/setters.
Downloads
1
Maintainers
Readme
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