When using JavaScipt, Base Types (with exception of Any) will automatically be converted to JavaScript types. If a conversion is not possible, an exception will be thrown (see Exception Handling).
The table below shows how base types and JavaScript types are converted:
Base Type | JavaScript Type | Additional Information |
---|---|---|
Blob | The support of type Blob is limited: Blobs cannot be created, but can be assigned to another blob. They have a toString() method which can be called internally to convert Blob to String. | |
Boolean | Boolean | |
DateTime | Date | |
Float | Number | |
Integer | Number | |
String | String |
Arrays are not native JavaScript arrays but are injected into the script via xUML parameters behave like standard JavaScript arrays but there are some limitations:
Array.isArray(xumlArray)
always returns false
.NULL
.xumlArray[0] = 0; xumlArray[3] = 3;
will result in an array looking like [0,NULL,NULL,3]
.With JavaScript operations, you can create objects of a complex type that has been defined in your data model. This is done by calling the constructor of the type, which is already included in JavaScript.
new
.Have a look at the PasswordGenerator class of the JavaScript_PasswortGenerator_Example:
The PasswordGenerator class resides in package Service . The full object type additionally is defined by a prefix urn and the (not visible) root package Data_Model.
Custom Type | |
---|---|
Full Object Type | urn:Data_Model.Service.PasswordGenerator |
Constructor Name | Data_Model_Service_PasswordGenerator |
Constructor Call | let myObject = new Data_Model_Service_PasswordGenerator(); |
For base types, this is similar:
Base Type | |
---|---|
Full Object Type | urn:Base_Types.String urn:Base_Components.Basic_Behavior.DateTime.DurationStructure |
Constructor Name | Base_Types_String Base_Components_Basic_Behavior_DateTime_DurationStructure |
Constructor Call | let myObject = new Base_Types_String(); |
Do not use underscores in your package or class names if you want to use these types in JavaScript as this may lead to conflicts with the name of the constructor.
would be the same. In such cases the behavior is explicitly undefined. |
JavaScript is dynamic while the xUML code of the Designer is well-regulated. When mixing Designer objects of complex type with JavaScript objects, the following rules apply:
Polymorphism is not implemented. The assignment of derived object types will be treated like an assignment between an object of complex type and a JavaScript object. The relation between parent and child classes is lost in a JavaScript operation.
We have a type Person that describes a person. An Employee is a special person (with all properties of a person) and an additional property company.
Action Script Input Parameters | Action Script Code | Output Parameter | |||
---|---|---|---|---|---|
person | {name: "John Doe"} |
| person | {name: "James Smith", } | |
employee | {name: "James Smith", } | ||||
JavaScript Input Parameters | JavaScript Code | Output Parameter | |||
person | {name: "John Doe"} |
| person | {name: "James Smith" } | |
employee | {name: "James Smith", } |