napi_property_descriptor
typedef struct {
// One of utf8name or name should be NULL.
const char* utf8name;
napi_value name;
napi_callback method;
napi_callback getter;
napi_callback setter;
napi_value value;
napi_property_attributes attributes;
void* data;
} napi_property_descriptor;
-
utf8name
:描述属性键的可选字符串,编码为 UTF8。必须为属性提供utf8name
或name
之一。¥
utf8name
: Optional string describing the key for the property, encoded as UTF8. One ofutf8name
orname
must be provided for the property. -
name
:可选的napi_value
,指向用作属性键的 JavaScript 字符串或符号。必须为属性提供utf8name
或name
之一。¥
name
: Optionalnapi_value
that points to a JavaScript string or symbol to be used as the key for the property. One ofutf8name
orname
must be provided for the property. -
value
:如果属性是数据属性,则通过属性的 get 访问检索到的值。如果传入,则将getter
、setter
、method
和data
设置为NULL
(因为不会使用这些成员)。¥
value
: The value that's retrieved by a get access of the property if the property is a data property. If this is passed in, setgetter
,setter
,method
anddata
toNULL
(since these members won't be used). -
getter
:执行对属性的获取访问时调用的函数。如果传入,则将value
和method
设置为NULL
(因为不会使用这些成员)。当从 JavaScript 代码访问属性时(或者如果使用 Node-API 调用执行对属性的获取),运行时将隐式调用给定函数。napi_callback
提供了更多详细信息。¥
getter
: A function to call when a get access of the property is performed. If this is passed in, setvalue
andmethod
toNULL
(since these members won't be used). The given function is called implicitly by the runtime when the property is accessed from JavaScript code (or if a get on the property is performed using a Node-API call).napi_callback
provides more details. -
setter
:执行属性的设置访问时调用的函数。如果传入,则将value
和method
设置为NULL
(因为不会使用这些成员)。当从 JavaScript 代码设置属性时(或者如果使用 Node-API 调用执行属性设置),运行时将隐式调用给定函数。napi_callback
提供了更多详细信息。¥
setter
: A function to call when a set access of the property is performed. If this is passed in, setvalue
andmethod
toNULL
(since these members won't be used). The given function is called implicitly by the runtime when the property is set from JavaScript code (or if a set on the property is performed using a Node-API call).napi_callback
provides more details. -
method
:设置此项使属性描述符对象的value
属性成为method
表示的 JavaScript 函数。如果传入,则将value
、getter
和setter
设置为NULL
(因为不会使用这些成员)。napi_callback
提供了更多详细信息。¥
method
: Set this to make the property descriptor object'svalue
property to be a JavaScript function represented bymethod
. If this is passed in, setvalue
,getter
andsetter
toNULL
(since these members won't be used).napi_callback
provides more details. -
attributes
:与特定属性关联的属性。参见napi_property_attributes
。¥
attributes
: The attributes associated with the particular property. Seenapi_property_attributes
. -
data
:如果调用此函数,回调数据将传递到method
、getter
和setter
。¥
data
: The callback data passed intomethod
,getter
andsetter
if this function is invoked.