Usage of JS function setTimeout() within a rule

Hi,

I am using openHAB 3.4.1 and have a problem with the JS function setTimeout. I’ve created a minimal example:

function greet(name, lastName) {
    console.log("Hello " + name + " " + lastName + "!");
}

setTimeout(greet, 1000, "John", "Doe");

Taking a look at the logs, the variables name and lastName are undefined within the greet function triggered by the timer. Can someone reproduce this? Or do I have a problem within my JS code?

Thanks alot!

you coud try your code in the developer tools of your browser (f12 key) and yield the same results

fixed:

function greet(name, lastName) {
    console.log("Hello " + name + " " + lastName + "!");
}

setTimeout(() => greet("John", "Doe"), 1000);

→ you pass a new function to setTimeout which holds your arguments.

Thank you, that works.