I assume this is a simple form you could do:
var app =
{
echo: function(txt)
{
alert(txt);
},
start: function(func)
{
this[func]("hello");
}
};
But you could argue a little smarter:
var app =
{
echo: function(txt)
{
alert(txt);
},
start: function(func)
{
var method = this[func];
var args = [];
for (var i = 1; i < arguments.length; i++)
args.push(arguments[i]);
method.apply(this, args);
}
};
So you can call him app.start("echo", "hello");
source
share