doc: advice to wrap your frontend code
Massimo Melina committed
Mar 23, 2025 at 16:59 UTC
18cef032cd58ee01fea96f557f991abda2a64ca1
1 file changed
+14
-4
dev-plugins.md
+14
-4
@@ -335,13 +335,23 @@ The `api` object you get as parameter of the `init` contains the following:
335
336
- `setInterval`, `setTimeout` same as standard js functions, but will automatically cancel if the plugin is unloaded.
337
338
-## Frontend specific
338
+## Frontend JS
339
340
-The following information applies to the default frontend, and may not apply to a custom one.
340
+The following information applies to the frontend bundled with HFS.
341
342
-Once your script is loaded into the frontend (via `frontend_js`), you will have access to the `HFS` object in the global scope.
342
+Once your script is loaded into the frontend (via `frontend_js`, refer above), it will be executed as any other script in the browser.
343
344
-The HFS object contains many properties:
344
+To avoid conflicts with other plugins, we suggest to wrap all your code like this:
345
+```js
346
+'use strict';{
347
+ // your code here
348
+ console.log('hi')
349
+}
350
+```
351
+
352
+### HFS object
353
+
354
+In frontend you will have access to the `HFS` object of the global scope, which has many properties:
355
- `onEvent` this is the main API function inside the frontend. Refer to dedicated section below.
356
- `apiCall`
357
- `useApi`