While trying to find a way to use nested classes in JS, I came up with this sort of thing:
class Character {
constructor() {
this.Info= class I {
constructor(name,value) {
this.name=name;
this.value=value;
}
};
}
bar () {
var trial = new this.Info("Goofy", 2);
alert(trial.name);
}
}
var test = new Character();
test.bar();
and it seems to work. However, I'm afraid this might be creating a new function object for each new
call, as I define the class in the constructor (which is executed at each new
call). Is there a more efficient way of doing this?
This question does not solve my issue as the author only wonders how to even have a nested class
; I'm already able to do that but I wonder if there's a more efficient way.