https://github.com/lamansky/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.
https://github.com/lamansky/modify-property
Last synced: 2 months ago
JSON representation
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.
- Host: GitHub
- URL: https://github.com/lamansky/modify-property
- Owner: lamansky
- License: mit
- Created: 2017-01-23T07:10:45.000Z (over 9 years ago)
- Default Branch: master
- Last Pushed: 2017-01-23T07:14:04.000Z (over 9 years ago)
- Last Synced: 2025-10-23T18:22:11.888Z (8 months ago)
- Language: JavaScript
- Homepage:
- Size: 1.95 KB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: readme.md
- License: license.txt
Awesome Lists containing this project
README
# modify-property
A [Node.js](https://nodejs.org/) module which lets you patch the descriptor of
an existing object property. This is primarily useful for swapping out getters or setters.
## Installation
```bash
npm install modify-property --save
```
## Usage
```javascript
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
```