You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
:param bool asString: *Experimental.* If true, the enum values are represented by plain strings in JavaScript, which is handy for basic operations like comparison and serialization.
812
+
:param enum_value_type valueType: The type of the enum values. This determines how the values are represented in JavaScript. If ``valueType`` is ``enum_value_type::object`` (default), the enum values are represented as an object with a ``.value`` field. If ``valueType`` is ``enum_value_type::number``, the enum values are represented as plain numbers. The default is ``enum_value_type::string``, the enum values are represented as the string names of the enum values.
Copy file name to clipboardExpand all lines: site/source/docs/porting/connecting_cpp_and_javascript/embind.rst
+17-5Lines changed: 17 additions & 5 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -825,20 +825,32 @@ type.
825
825
Module.OldStyle.ONE;
826
826
Module.NewStyle.TWO;
827
827
828
-
If you set the `asString` parameter to `true` when registering the enum, the enum values will be represented as plain strings in JavaScript.
828
+
You can simplify how enums are represented in JavaScript by setting the `enum_value_type` parameter when registering the enum.
829
+
The default value type is `enum_value_type::object`, which binds the enum values to objects with a `value` property.
830
+
Other options are `enum_value_type::number`, which binds the enum values to their plain integer value, and `enum_value_type::string`, which binds the enum values to the string of their name.
0 commit comments