napi_property_attributes
typedef enum {
napi_default = 0,
napi_writable = 1 << 0,
napi_enumerable = 1 << 1,
napi_configurable = 1 << 2,
// Used with napi_define_class to distinguish static properties
// from instance properties. Ignored by napi_define_properties.
napi_static = 1 << 10,
// Default for class methods.
napi_default_method = napi_writable | napi_configurable,
// Default for object properties, like in JS obj[prop].
napi_default_jsproperty = napi_writable |
napi_enumerable |
napi_configurable,
} napi_property_attributes;
napi_property_attributes
是用于控制在 JavaScript 对象上设置的属性行为的标志。除 napi_static
外,它们对应于 ECMAScript 语言规范 的 第 6.1.7.1 节 中列出的属性。它们可以是以下一个或多个位标志:
¥napi_property_attributes
are flags used to control the behavior of properties
set on a JavaScript object. Other than napi_static
they correspond to the
attributes listed in Section 6.1.7.1
of the ECMAScript Language Specification.
They can be one or more of the following bitflags:
-
napi_default
:没有在属性上设置显式属性。默认情况下,属性是只读的,不可枚举且不可配置。¥
napi_default
: No explicit attributes are set on the property. By default, a property is read only, not enumerable and not configurable. -
napi_writable
:该属性是可写的。¥
napi_writable
: The property is writable. -
napi_enumerable
:该属性是可枚举的。¥
napi_enumerable
: The property is enumerable. -
napi_configurable
:该属性可按照 ECMAScript 语言规范 的 第 6.1.7.1 节 中的定义进行配置。¥
napi_configurable
: The property is configurable as defined in Section 6.1.7.1 of the ECMAScript Language Specification. -
napi_static
:该属性将被定义为类的静态属性,而不是默认的实例属性。这仅由napi_define_class
使用。它被napi_define_properties
忽略。¥
napi_static
: The property will be defined as a static property on a class as opposed to an instance property, which is the default. This is used only bynapi_define_class
. It is ignored bynapi_define_properties
. -
napi_default_method
:就像 JS 类中的方法一样,该属性是可配置和可写的,但不可枚举。¥
napi_default_method
: Like a method in a JS class, the property is configurable and writeable, but not enumerable. -
napi_default_jsproperty
:就像 JavaScript 中通过赋值设置的属性一样,属性是可写、可枚举和可配置的。¥
napi_default_jsproperty
: Like a property set via assignment in JavaScript, the property is writable, enumerable, and configurable.