Importing functions from JavaScript file inside CustomJS

Hello everybody,

I am currently writing a bokeh application where I use a bunch of CustomJS as callbacks. In these call-backs I use a bunch of the same functions. So I would like to save them in a js and I would like to import them into my callbacks.

So what I do is

import { a } from './b.js'

And I receive the following output in my JS console in the browser:

SyntaxError: Unexpected token '{'. import call expects exactly one argument.

I am not quite sure why, and how do I fix it?

Many thanks in advance,
Daniel

JS import/require functionality is a constantly changing mess with different support on different platforms, and I would strongly advise against attempting to use it in a code that’s not going through any compilation step.

The simplest option in your case is to create a global JS object in b.js and use that object and its methods in all relevant CustomJS code.

@p-himik Thanks for your comment, I think I will stick to your advice. Many thanks!