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

Difference between JS-Scripting and JS223-Scripting #139

Closed dilyanpalauzov closed 2 years ago

dilyanpalauzov commented 2 years ago

https://www.openhab.org/docs/configuration/jsr223.html says, that one possible way for scripting is to use JavaScript, by putting .js files under opehnab/automation/jsr223/.

https://www.openhab.org/addons/automation/jsscripting/ presents another way to JavaScript-scripting, by installing .js files under opehab/automation/js/.

I cannot find anywhere information, what are the differences between both approaches and when to use which one. Both approaches obviously use JavaScript.

Please extend the documentation to state, how JavaScript scripting differs from JSR223-JavaScript scripting.

florian-h05 commented 2 years ago

Hello @dilyanpalauzov,

the difference is that JSR223 JavaScript is based on an older JavaScript engine called NashornJS that only supports ECMAScript 5.1. Furthermore, you have to use the raw Java APIs with JSR223 which is quite complicated.

JS Scripting instead supports the latest ECMAScript 6 and provides this library (openHAB-js) that „translates“ between JavaScript and the raw Java APIs. This makes the usage of JS Scripting much easier and allows you to use pure JS without worrying about the Java part. Therefore it is recommended to use JS Scripting.

dilyanpalauzov commented 2 years ago

This recommendation is nowhere written and the differences between the two systems are not outlined.

florian-h05 commented 2 years ago

I am now aware of this thanks to to your issue.

I'll move this issue to the docs repository and provide a PR that updates the docs to fix this.