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

Any variable

value2

any

Any variable

bTypeSafe

boolean

 

Return value

Type

Description

boolean

True if the content of the variable is the same.

tchmi_equal 1:

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