JavaScript support was added last - and it has two major problems.
- Using "import" and "export" is not possible because your code will be executed in the eval function - the structure of the javascript language prohibits this.
I tried to get around it myself, but I couldn't.
I tried adding a js file as assets but MicroStudio does not allow adding files ending in *.js.
I decided to add the *.js code, but changing the end of the file to *.txt and importing it using the 'import(url)' function - but now the browser was blocking the download, saying that it had blocked the request to eliminate any possible ambiguities (they introduced this in IE 8.0) .
I have one more idea - I'll let you know how it turns out.
- MicroStudio does not correctly show code parsing/execution errors. Because your code must go through a call before being added to executable code:
eval( you_code_javascript_string ) .
If parsing and execution are successful, the code is added and can be used.
If there is an error there will always be an error message on line 34.
This makes debugging very difficult.
You need to add the JavaScript code in small fragments and try to run it - if there is an error, it is in the fragment you added.
If you add the entire library at once and run it and there is an error - you have no idea where the error is.
How to add large libraries to a project.
The easiest way is to add one file with javascript code.
You cannot use the words "import" and "export" in .
What to do if the library uses these words??
If the library uses "export"
class ABC{};
DEF(){}
GHI = function(){}
export { ABC, DEF, GHI }
then
you wrap all the code in a function
nameLib = function()[
class ABC{};
DEF(){}
GHI = function(){}
return { ABC, DEF, GHI }
}
and from the main file
init = function(){
name = nameLib()
}
now the entire library is under the "name" variable.
See the code I moved >>
https://microstudio.io/i/Loginus/three/
https://microstudio.io/i/Loginus/pixi3d/
https://microstudio.io/i/Loginus/consolelog/
https://microstudio.io/i/Loginus/quickengineinjs/
However, it is worse when there are many files and they have the word "import" in them. Now, to add them correctly, you need to wrap each file in a function that returns what you export.
You also need to call them in the right order so as not to open the file
XYZ which requires classes and functions from the MNO file.