0
I need to start objects dynamically with Javascript
Ex:
Example class:
function sayhello() {
    this.init = function() {
        alert('Hello');
    }
}
Function to dynamically load and instantiate classes:
function iniciaClasse(nomeDaClasse) {
    return new nomeDaClasse();
}
Final code (for implementation):
var variavelqualquer = iniciaClasse('sayhello');
The problem:
This is returning me a mistake, and I understand more or less why, once I pass a string in the parameter nomeDaClasse, since I don’t have the class builder being instantiated right away.
The function iniciaClasse() is a module Loader, and will load, start and return the class I inform, therefore, when I call such a function, the constructor (sayhello) doesn’t exist yet.
So...
If I do: iniciaClasse(sayHello) - I get a mistake because sayHello() does not yet exist
If I do: iniciaClasse('sayHello') - I get an error because the parameter passed is a string (I think that’s why)
Is there any way to fix it?
tries to use Singleton project pattern.
– Marcus v1n1b0y Vinicius
Have any answers solved what was in doubt? Do you need something else to be improved? Do you think it is possible to accept it now?
– Maniero