jaymc Posted June 10, 2008 Share Posted June 10, 2008 Dont as why, but I need this to work function beans() { alert('hello'); } var do_function = beans do_function(); In essance do_function() is really beans(); so I could execute the beans() function using either of the below do_function(); beans(); This doesnt work, maybe i am missing something, how can i achieve this? Link to comment https://forums.phpfreaks.com/topic/109623-solved-treat-var-as-a-function/ Share on other sites More sharing options...
hansford Posted June 10, 2008 Share Posted June 10, 2008 function beans() { alert('hello'); } var beans = do_function(); Link to comment https://forums.phpfreaks.com/topic/109623-solved-treat-var-as-a-function/#findComment-562331 Share on other sites More sharing options...
jaymc Posted June 10, 2008 Author Share Posted June 10, 2008 function beans() { alert('hello'); } var beans = do_function(); Huh? So how do I execute beans() / do_function? try and use my first example as thats exactly how I must use it Link to comment https://forums.phpfreaks.com/topic/109623-solved-treat-var-as-a-function/#findComment-562339 Share on other sites More sharing options...
DarkWater Posted June 10, 2008 Share Posted June 10, 2008 Pretty sure that doesn't work in JS. I know it works in PHP... function foo() { echo "Bar."; } $foobar = 'foo'; $foobar(); Link to comment https://forums.phpfreaks.com/topic/109623-solved-treat-var-as-a-function/#findComment-562343 Share on other sites More sharing options...
hansford Posted June 10, 2008 Share Posted June 10, 2008 function beans() { alert('hello'); do_function(); } function do_function() { alert('hello there') } beans(); ----------------------------OR function do_function() { alert('hello'); } var beans = do_function; beans(); Link to comment https://forums.phpfreaks.com/topic/109623-solved-treat-var-as-a-function/#findComment-562391 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.