javascript dynamic classes

Solutions on MaxInterview for javascript dynamic classes by the best coders in the world

showing results for - "javascript dynamic classes"
Leonardo
25 Sep 2020
1JavaScript "classes", just like any other object, can be dynamically created. So, yes, this can be done.
2
3You would do something like this in the code handling the AJAX response (assuming that the AJAX response was providing the name of the new "class", and it's in a variable called newClassName):
4
5window[newClassName] = function() {
6  // New class name constructor code
7}
8
9window[newClassName].prototype = {
10
11  someProperty: "someValue",
12
13  someMethod: function(a, b) {
14  },
15
16  someOtherMethod: function(x) {
17  }
18}