openhab / openhab-js

openHAB JavaScript Library for JavaScript Scripting Automation
https://www.openhab.org/addons/automation/jsscripting/
Eclipse Public License 2.0
38 stars 31 forks source link

[docs] Add a note about let & const not working in UI scripts #235

Closed florian-h05 closed 1 year ago

florian-h05 commented 1 year ago

Although all our code examples try to avoid using let or const and instead use var, we should add a note to the docs to clearly state that let and const are not working in UI rules due to some limitations in openHAB.

@rkoshak WDYT?

rkoshak commented 1 year ago

I think it's a good idea. However, maybe we should also present how a user can wrap their script in an anonymous function which would allow them to use let and const.

Either way, we need to make sure to include the fact that it's only at the top level of the script where they cannot be used. Inside functions it's fine.