File: propertylvalue.md

package info (click to toggle)
node-addon-api 5.0.0-6%2Bdeb12u1
  • links: PTS, VCS
  • area: main
  • in suites: bookworm
  • size: 1,920 kB
  • sloc: cpp: 7,531; ansic: 5,297; javascript: 4,654; makefile: 7
file content (50 lines) | stat: -rw-r--r-- 1,250 bytes parent folder | download | duplicates (3)
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
41
42
43
44
45
46
47
48
49
50
# PropertyLValue 

The `Napi::Object::PropertyLValue` class is a helper class provided by
`Napi::Object` to allow more intuitive assignment of properties.

## Example
```cpp
#include <napi.h>

using namespace Napi;

Void Init(Env env) {
  // Create a new instance
  Object obj = Object::New(env);

  // Assign a value to a property. 
  obj["hello"] = "world";
}
```

In the above example, `obj["hello"]` returns a `Napi::Object::PropertyLValue`
whose `operator=()` method accepts a string which will become the value of the
"hello" property of the newly created object.

In general, `obj[key] = value` is the equivalent of `obj.Set(key, value)`, where
the types of `key` and `value` are all those supported by
[`Napi::Object::Set()`](object.md#set).

## Methods

### operator Value()

```cpp
operator Value() const;
```

Implicitly casts this `Napi::Object::PropertyLValue` to a `Napi::Value`.

### operator =()

```cpp
template <typename ValueType>
PropertyLValue& operator =(ValueType value);
```

* `[in] value` a value to assign to the property referred to by the
  `Napi::Object::PropertyLValue`. The type of the value is one of the types
  supported by the second parameter of [`Napi::Object::Set()`](object.md#set).

Returns a self-reference.