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。必须为属性提供 utf8namename 之一。

    ¥utf8name: Optional string describing the key for the property, encoded as UTF8. One of utf8name or name must be provided for the property.

  • name:可选的 napi_value,指向用作属性键的 JavaScript 字符串或符号。必须为属性提供 utf8namename 之一。

    ¥name: Optional napi_value that points to a JavaScript string or symbol to be used as the key for the property. One of utf8name or name must be provided for the property.

  • value:如果属性是数据属性,则通过属性的 get 访问检索到的值。如果传入,则将 gettersettermethoddata 设置为 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, set getter, setter, method and data to NULL (since these members won't be used).

  • getter:执行对属性的获取访问时调用的函数。如果传入,则将 valuemethod 设置为 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, set value and method to NULL (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:执行属性的设置访问时调用的函数。如果传入,则将 valuemethod 设置为 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, set value and method to NULL (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 函数。如果传入,则将 valuegettersetter 设置为 NULL(因为不会使用这些成员)。napi_callback 提供了更多详细信息。

    ¥method: Set this to make the property descriptor object's value property to be a JavaScript function represented by method. If this is passed in, set value, getter and setter to NULL (since these members won't be used). napi_callback provides more details.

  • attributes:与特定属性关联的属性。参见 napi_property_attributes

    ¥attributes: The attributes associated with the particular property. See napi_property_attributes.

  • data:如果调用此函数,回调数据将传递到 methodgettersetter

    ¥data: The callback data passed into method, getter and setter if this function is invoked.