I need to create an instance of classes from a certain javascript file which contains 3 classes and call the methods of that classes from another javascript file. Classes in main javascript file is like:
function Class1(param1, param2) {
this.openTag;
this.closeTag;
this.htmlTags;
this.openTag = '<div id="' + this.elementId + '">';
this.closeTag = '</div>';
this.htmlTags = {
sectionTitle: {
openTag: '<h2 class="class1">',
closeTag: '</h2>'
},
group: {
openTag: '<div class="class2">',
closeTag: '</div>'
},
table: {
openTag: '<table class="class3">',
closeTag: '</table>'
}
}
...
}
And methods like:
Class1.prototype.someName = function (index) {
var outputHtml = '';
var text = this.tableHeaders[index] || '';
outputHtml += '<th>' + text + '</th>';
return outputHtml;
}
How can I create an instance of these classes and call them from another javascript file or how can I use them in HTML? When I try to do ES6 imports/exports or creating new object referring to those classes it gives me this error:
Access to script at 'file:///Users/user/Desktop/project/someName.js' from origin 'null' has been blocked by CORS policy: Cross origin requests are only supported for protocol schemes: http, data, chrome, chrome-extension, https.
&
app.js:1 Uncaught SyntaxError: Cannot use import statement outside a module