-
Notifications
You must be signed in to change notification settings - Fork 459
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Documents the helper class `Napi::Object::PropertyLValue`. Fixes: #924
- Loading branch information
1 parent
12c548b
commit 929709d
Showing
2 changed files
with
57 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,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. |