Is this possible to have a class in JS and declare 2 method names from string? I mean something like this:
function MyClass()
{
var methods = ['hello', 'hey'];
for (var i in methods)
{
this[methods[i]] = function()
{
alert('This is method ' + methods[i]);
}
}
}
This should create me a class with function hello and hey. I need to create a few functions which have very similar body but different names. I don't want to use eval, so the code can be compiled.
var c = MyClass();It is indeed working withnew MyClass. Thank you!