tchmi_equal
[ Function ]
function tchmi_equal(value1: any, value2: any, bTypeSafe: boolean = true): boolean;
Checks whether two variables are equal.
In JavaScript, simple data types (such as Booleans or numbers) are copied when used (by value). However, if a data type is complex, a reference is used (by reference), so that manipulation of the supposed copy also changes the original value.
A comparison for equality is not trivial with values such as SolidColor, for example since the simple ===
operator checks the references but not the content.
The function tchmi_equal
can be used instead.
Parameter
Name | Type | Description |
---|---|---|
value1 | Any variable | |
value2 | Any variable | |
bTypeSafe |
|
Return value
Type | Description |
---|---|
True if the content of the variable is the same. |
Available from 1.8 |
Sample - JavaScript
var myColor = {color: 'red'};
var myColor2 = {color: 'red'};
TcHmi.Log.debug(
'JS compare: ' + (myColor === myColor2) +
' tchmi_equal: ' + tchmi_equal(myColor, myColor2)); // JS compare: false tchmi_equal: true