File: .verb.md

package info (click to toggle)
node-define-property 2.0.2-1
  • links: PTS, VCS
  • area: main
  • in suites: bullseye, buster, sid
  • size: 196 kB
  • sloc: makefile: 14; sh: 5
file content (40 lines) | stat: -rw-r--r-- 990 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
## Release history

See [the CHANGELOG](changelog.md) for updates.

## Usage

**Params**

- `object`: The object on which to define the property.
- `key`: The name of the property to be defined or modified.
- `value`: The value or descriptor of the property being defined or modified.

```js
var define = require('{%= name %}');
var obj = {};
define(obj, 'foo', function(val) {
  return val.toUpperCase();
});

// by default, defined properties are non-enumberable
console.log(obj);
//=> {}

console.log(obj.foo('bar'));
//=> 'BAR'
```

**defining setters/getters**

Pass the same properties you would if using [Object.defineProperty][object] or [Reflect.defineProperty][reflect]. 

```js
define(obj, 'foo', {
  set: function() {},
  get: function() {}
});
```

[object]: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/defineProperty
[reflect]: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Reflect/defineProperty