Creating a function object from its string name

satya - Wed Oct 10 2012 09:18:17 GMT-0400 (Eastern Daylight Time)

Here is my previous notes on this

Here is my previous notes on this

satya - Wed Oct 10 2012 09:19:18 GMT-0400 (Eastern Daylight Time)

Here is the source code


function testFuncObject()
{
    var f = getFunctionObject("quickTest");
    if (f == null)
    {
        alert("sorry");
    }
    f();
}

function quickTest()
{
    alert('quick test');
}


//returns a function object given its name
//if the function is undefined return null
function getFunctionObject(functionname)

{
    var funcobject;
    eval("funcobject = " + functionname + ";");
    if (typeof(funcobject) == "function")
    {
        return funcobject;
    }
    else
    {
        //null is a javascript object
        return null;
    }
}