0
Answered
Es6 Modules
Does testastic support importing and exporting modules between js files? For some reason, the following code doesn’t seem to work https://feedback.textasticapp.com/communities/1-textastic-for-ios#
// file1.js
function sum(num1, num2) {
return num1 + num2;
}
export default sum;
// file2.js
import sum from "./file2.js";
console.log(sum(1, 2)); // instead of 3 I get the message “SyntaxError: Unexpected identifier 'sum'. import call expects
exactly one argument.”
note: file1 and file2 are in the same folder.
Thanks for your help.
Errol
Customer support service by UserEcho
ps, I am running the main.js file from an index.html file.
Hello,
you need to make sure that you use type="module" in the script tag in the html file, like this:
Also, it should probably be
in the first line of file2.js.
It works! Thanks for a great app and your excellent surpport.