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? Quote 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(); Quote 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 Quote 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(); Quote 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(); Quote 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
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.