Skip to content

Updated Object documentation#254

Closed
anisha-rohra wants to merge 5 commits intonodejs:masterfrom
anisha-rohra:docs
Closed

Updated Object documentation#254
anisha-rohra wants to merge 5 commits intonodejs:masterfrom
anisha-rohra:docs

Conversation

@anisha-rohra
Copy link
Copy Markdown

No description provided.

Comment thread doc/object.md
if you don't find what you need please refer to:
[C++ wrapper classes for the ABI-stable C APIs for Node.js](https://nodejs.github.io/node-addon-api/) No newline at end of file
Object is a Javascript object value. A common usecase is to assign many values to a single object.

Copy link
Copy Markdown
Member

@mhdawson mhdawson May 1, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

My suggestion for the intro would be:

The Object class corresponds to a JavaScript object. It is extended by following node-addon-api classes that you may use when working with more specific types:

This class provides a number of convenience methods, most of which are used to set or set properties on a JavaScript object. For example, Set() and Get().

Comment thread doc/object.md Outdated
- `[in] key`: The property that is being assigned a value.
- `[in] value`: The property that is being assigned to a key.

Assigns the value to the key .
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

extra space

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

How about

Add a property with the specified key with the specified value to the object.

Comment thread doc/object.md Outdated
```cpp
void Napi::Object::Set (____ key, ____ value);
```
- `[in] key`: The property that is being assigned a value.
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

How about

The name for the property being assigned.

Comment thread doc/object.md Outdated
void Napi::Object::Set (____ key, ____ value);
```
- `[in] key`: The property that is being assigned a value.
- `[in] value`: The property that is being assigned to a key.
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

How about

The value being assigned to the property

Comment thread doc/object.md
Alternatively, the key can be any of the following types:
- `const char*`
- `const std::string&`
- `uint32_t`
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This part I find a bit confusing. I might be easier to just say key's can be of the following types, and values can be of the following types.

Comment thread doc/object.md Outdated
```cpp
Value Napi::Object::Get(____ key);
```
- `[in] key`: The property whose assigned value is being returned.
Copy link
Copy Markdown
Member

@mhdawson mhdawson May 1, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

How about
The name of the property to return the value for.

Comment thread doc/object.md
- `const char *`
- `const std::string &`
- `uint32_t`

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We should say what it returns if the property does not exist.

Comment thread doc/object.md Outdated
```cpp
bool Napi::Object::Has (____ key) const;
```
- `[in] key`: The property that is being checked for having an assigned value.
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

How about
the name of the property to check.

Comment thread doc/object.md Outdated
```
- `[in] key`: The property that is being checked for having an assigned value.

Returns a `bool` that is *true* if the `key` has a value property associated with it and *false* otherwise.
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

..if the object has a property name key` and false otherwise.

Comment thread doc/object.md
### Operator[]()

```cpp
PropertyLValue<std::string> Napi::Object::operator[] (const char* utf8name);
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Some examples in the introduction which shows using these might help .

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not sure how to use these myself, do you know of any existing examples I can take a look at?

Comment thread doc/object.md Outdated

Returns an indexed property or array element as a [Value](value.md).

### Example
Copy link
Copy Markdown
Member

@mhdawson mhdawson May 1, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think moving the examples up into the intro would be better and adding some that use the operators as well.

Copy link
Copy Markdown
Member

@mhdawson mhdawson left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

mhdawson pushed a commit that referenced this pull request May 30, 2018
PR-URL: #254
Reviewed-By: Michael Dawson <michael_dawson@ca.ibm.com>
@mhdawson
Copy link
Copy Markdown
Member

Landed as 43ff9fa

@mhdawson mhdawson closed this May 30, 2018
kevindavies8 added a commit to kevindavies8/node-addon-api-Develop that referenced this pull request Aug 24, 2022
PR-URL: nodejs/node-addon-api#254
Reviewed-By: Michael Dawson <michael_dawson@ca.ibm.com>
Marlyfleitas added a commit to Marlyfleitas/node-api-addon-Development that referenced this pull request Aug 26, 2022
PR-URL: nodejs/node-addon-api#254
Reviewed-By: Michael Dawson <michael_dawson@ca.ibm.com>
wroy7860 added a commit to wroy7860/addon-api-benchmark-node that referenced this pull request Sep 19, 2022
PR-URL: nodejs/node-addon-api#254
Reviewed-By: Michael Dawson <michael_dawson@ca.ibm.com>
johnfrench3 pushed a commit to johnfrench3/node-addon-api-git that referenced this pull request Aug 11, 2023
PR-URL: nodejs/node-addon-api#254
Reviewed-By: Michael Dawson <michael_dawson@ca.ibm.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants