napi_define_properties


napi_status napi_define_properties(napi_env env,
                                   napi_value object,
                                   size_t property_count,
                                   const napi_property_descriptor* properties); 
  • [in] env:调用 Node-API 时所处的环境。
  • [in] 对象:要从中获取属性的对象。
  • [in] property_countproperties 数组中的元素数量。
  • [in] properties:属性描述符数组。

如果 API 成功,则返回 napi_ok

【Returns napi_ok if the API succeeded.】

此方法允许在给定对象上高效地定义多个属性。使用属性描述符(见 napi_property_descriptor)来定义属性。给定一个这样的属性描述符数组,此 API 将按照 DefineOwnProperty()(在 ECMA-262 规范的 定义自有属性部分 中描述)定义的方式,一次在对象上设置一个属性。

【This method allows the efficient definition of multiple properties on a given object. The properties are defined using property descriptors (see napi_property_descriptor). Given an array of such property descriptors, this API will set the properties on the object one at a time, as defined by DefineOwnProperty() (described in Section DefineOwnProperty of the ECMA-262 specification).】