My question is quite simple. In Php you can call a function including a string in the name of your function. Example :
function setName(name){
$this->name = name;
}
$string = 'Name';
$method = 'set'.$string;
if(method_exists($this, $method)
$this->$method($_POST['name']);
So I wanted to know if there was something like this in Javascript... For now, I'm using a switch to check the body id and call the function. This is my code :
switch($('body').attr('id'))
{
case 'index':
app.index.init();
break;
case 'login':
app.login.inint();
break;
};
app.index = {
init : function(){
console.log('Hola Mundo');
}
};
So I was wondering if I could make something like this :
var id = $('body').attr('id');
app.id.init();
thanks for your answers.