File tree Expand file tree Collapse file tree 2 files changed +57
-4
lines changed
Expand file tree Collapse file tree 2 files changed +57
-4
lines changed Original file line number Diff line number Diff line change @@ -232,28 +232,31 @@ void Napi::Object::DefineProperties (____ properties)
232232
233233Defines properties on the object.
234234
235- ### Operator[ ]()
235+ ### operator\[\ ]()
236236
237237```cpp
238238Napi::PropertyLValue<std::string> Napi::Object::operator[] (const char* utf8name);
239239```
240240- ` [in] utf8name ` : UTF-8 encoded null-terminated property name.
241241
242- Returns a [ ` Napi::PropertyLValue ` ] ( propertylvalue.md ) as the named property or sets the named property.
242+ Returns a [ ` Napi::Object::PropertyLValue ` ] ( propertylvalue.md ) as the named
243+ property or sets the named property.
243244
244245``` cpp
245246Napi::PropertyLValue<std::string> Napi::Object::operator [] (const std::string& utf8name);
246247```
247248- ` [in] utf8name ` : UTF-8 encoded property name.
248249
249- Returns a [ ` Napi::PropertyLValue ` ] ( propertylvalue.md ) as the named property or sets the named property.
250+ Returns a [ ` Napi::Object::PropertyLValue ` ] ( propertylvalue.md ) as the named
251+ property or sets the named property.
250252
251253``` cpp
252254Napi::PropertyLValue<uint32_t > Napi::Object::operator [] (uint32_t index);
253255```
254256- ` [in] index ` : Element index.
255257
256- Returns a [ ` Napi::PropertyLValue ` ] ( propertylvalue.md ) or sets an indexed property or array element.
258+ Returns a [ ` Napi::Object::PropertyLValue ` ] ( propertylvalue.md ) or sets an
259+ indexed property or array element.
257260
258261``` cpp
259262Napi::Value Napi::Object::operator [] (const char * utf8name) const ;
Original file line number Diff line number Diff line change 1+ # PropertyLValue
2+
3+ The ` Napi::Object::PropertyLValue ` class is a helper class provided by
4+ ` Napi::Object ` to allow more intuitive assignment of properties.
5+
6+ ## Example
7+ ``` cpp
8+ #include < napi.h>
9+
10+ using namespace Napi ;
11+
12+ Void Init (Env env) {
13+ // Create a new instance
14+ Object obj = Object::New(env);
15+
16+ // Assign a value to a property.
17+ obj[ "hello"] = "world";
18+ }
19+ ```
20+
21+ In the above example, `obj["hello"]` returns a `Napi::Object::PropertyLValue`
22+ whose `operator=()` method accepts a string which will become the value of the
23+ "hello" property of the newly created object.
24+
25+ In general, `obj[key] = value` is the equivalent of `obj.Set(key, value)`, where
26+ the types of `key` and `value` are all those supported by
27+ [`Napi::Object::Set()`](object.md#set).
28+
29+ ## Methods
30+
31+ ### operator Value()
32+
33+ ```cpp
34+ operator Value() const;
35+ ```
36+
37+ Implicitly casts this ` Napi::Object::PropertyLValue ` to a ` Napi::Value ` .
38+
39+ ### operator =()
40+
41+ ``` cpp
42+ template <typename ValueType>
43+ PropertyLValue& operator =(ValueType value);
44+ ```
45+
46+ * ` [in] value ` a value to assign to the property referred to by the
47+ ` Napi::Object::PropertyLValue ` . The type of the value is one of the types
48+ supported by the second parameter of [ ` Napi::Object::Set() ` ] ( object.md#set ) .
49+
50+ Returns a self-reference.
You can’t perform that action at this time.
0 commit comments