You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: README.md
+3-20Lines changed: 3 additions & 20 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -178,26 +178,6 @@ console.log(event.itemState.toString() == "test") // OK
178
178
179
179
The openHAB JavaScript Scripting runtime attempts to provide a familiar environment to JavaScript developers.
180
180
181
-
### `let` and `const`
182
-
183
-
Due to the way how openHAB runs UI based scripts, `let`, `const` and `class` are not supported at top-level.
184
-
Use `var` instead or wrap your script inside a self-invoking function:
185
-
186
-
```javascript
187
-
// Wrap script inside a self-invoking function:
188
-
(function (data) {
189
-
constC='Hello world';
190
-
console.log(C);
191
-
})(this.event);
192
-
193
-
// Defining a class using var:
194
-
var Tree =class {
195
-
constructor (height) {
196
-
this.height= height;
197
-
}
198
-
}
199
-
```
200
-
201
181
### `require`
202
182
203
183
Scripts may include standard NPM based libraries by using CommonJS `require`.
@@ -1587,6 +1567,9 @@ Follow these steps to create your own library (it's called a CommonJS module):
1587
1567
1. Tar it up by running `npm pack` from your library's folder.
1588
1568
1. Install it by running `npm install <path-to-library-folder>/<name>-<version>.tgz` from the `automation/js` folder.
1589
1569
1. After you've installed it with `npm`, you can continue development of the library inside `node_modules`.
1570
+
1. As you might have already noticed, the JavaScript Scripting add-on is reloading a script as soon as one of its dependencies changes.
1571
+
When developing a library inside `node_modules`, this can cause regular reloads.
1572
+
To avoid this situation, you can disable dependency tracking in the JavaScript Scripting add-on settings (you need to tick "show advanced" for the setting to come up).
1590
1573
1591
1574
It is also possible to upload your library to [npm](https://npmjs.com) to share it with other users.
0 commit comments