vendredi 22 janvier 2016

javascript : get a global variable from its name as string (reflection)

I saw a lot of answer to call a method from a given object using a string, but no one to get the object itself. I would like something like that

var a
var b
var c

function getObject(objectAsString)
{
return getMyObject(objectAsString);
}

then if I write

var obj=getObject("a")

my result is obj=a

Is there a function "getMyObject"? Thanks





Aucun commentaire:

Enregistrer un commentaire