I'm reloading/re-executing my javascript using jquery's getScript function with
jQuery('#my-script').empty();
jQuery.getScript( 'js/myscript.js', function() {
});
This worked fine with jquery V1.x or V2.x. Since jquery v3.x the reload works but the re-execute of script fails with error
uncaught SyntaxError: redeclaration of let varname
where "varname" is a class like
class varname {
constructor(x, y) {
this.x = x;
this.y = y;
}
method1 { .. }
}
I think the problem is caused by the ES6 Javascript standard. But I could not find a solution to fix my problem other than use the older jquery versions. Has anybody a clue how to solve this?
I've solved the problem - it is caused by ES6 standard, which changes the process of scoping of variables. I had to define my classes as:
var varname = class varname {...}
This solved the issue. Just defining
class varname {...}
will result in a definition of.
let varname = class varname {...}
and this wil cause a failed redeclaration.