WebGL: How to call common JS func from an imported JS func?

(For the WebGL target: ) The page here ( https://docs.unity3d.com/Manual/webgl-interactingwithbrowserscripting.html ) shows how to create JavaScript functions callable from Unity3D C# scripts.

But how do I call a common JS function from those exported functions? The two obvious attempts both failed to work:


mergeInto(LibraryManager.library, {
Foo: function() {
common(1);
},
Bar: function() {
common(2);
},
common: function(val) {
},
});

Unsurprisingly doesn’t work, because “common” isn’t a known function name, but rather just another name in the anonymous object being defined. But then, the following dsoesn’t work either:


function common(val) {
};

mergeInto(LibraryManager.library, {
Foo: function() {
common(1);
},
Bar: function() {
common(2);
},
);

That fails at runtime, claiming “common” isn’t defined.

So just how do I call another JS function from a Unity3D-imported JS function?

Look below on that page, you have to define the functions first like so:

[DllImport("__Internal")]
private static extern void Foo();
[DllImport("__Internal")]
private static extern void Bar();
[DllImport("__Internal")]
private static extern void common(int value);

But I am not sure if you can call methods that you define in that call. Maybe move declaration of common on top?

mergeInto(LibraryManager.library, {
common: function(val) {
},
},
Foo: function() {
common(1);
},
Bar: function() {
common(2);
});