Name |
Date |
Size |
#Lines |
LOC |
||
---|---|---|---|---|---|---|
.. | - | - | ||||
.npmignore | D | 12-May-2024 | 12 | 1 | 1 | |
.travis.yml | D | 12-May-2024 | 119 | 10 | 10 | |
LICENSE.md | D | 12-May-2024 | 1.1 KiB | 12 | 7 | |
README.md | D | 12-May-2024 | 1.7 KiB | 48 | 30 | |
package.json | D | 12-May-2024 | 1.3 KiB | 59 | 58 | |
prr.js | D | 12-May-2024 | 1.5 KiB | 63 | 48 | |
test.js | D | 12-May-2024 | 3.8 KiB | 170 | 148 |
README.md
1# prr [](http://travis-ci.org/rvagg/prr) 2 3An sensible alternative to `Object.defineProperty()`. Available in npm and Ender as **prr**. 4 5## Usage 6 7Set the property `'foo'` (`obj.foo`) to have the value `'bar'` with default options (`'enumerable'`, `'configurable'` and `'writable'` are all `false`): 8 9```js 10prr(obj, 'foo', 'bar') 11``` 12 13Adjust the default options: 14 15```js 16prr(obj, 'foo', 'bar', { enumerable: true, writable: true }) 17``` 18 19Do the same operation for multiple properties: 20 21```js 22prr(obj, { one: 'one', two: 'two' }) 23// or with options: 24prr(obj, { one: 'one', two: 'two' }, { enumerable: true, writable: true }) 25``` 26 27### Simplify! 28 29But obviously, having to write out the full options object makes it nearly as bad as the original `Object.defineProperty()` so we can simplify. 30 31As an alternative method we can use an options string where each character represents a option: `'e'=='enumerable'`, `'c'=='configurable'` and `'w'=='writable'`: 32 33```js 34prr(obj, 'foo', 'bar', 'ew') // enumerable and writable but not configurable 35// muliple properties: 36prr(obj, { one: 'one', two: 'two' }, 'ewc') // configurable too 37``` 38 39## Where can I use it? 40 41Anywhere! For pre-ES5 environments *prr* will simply fall-back to an `object[property] = value` so you can get close to what you want. 42 43*prr* is Ender-compatible so you can include it in your Ender build and `$.prr(...)` or `var prr = require('prr'); prr(...)`. 44 45## Licence 46 47prr is Copyright (c) 2013 Rod Vagg [@rvagg](https://twitter.com/rvagg) and licensed under the MIT licence. All rights not explicitly granted in the MIT license are reserved. See the included LICENSE.md file for more details. 48