Graal Forums

Graal Forums (https://forums.graalonline.com/forums/index.php)
-   Future Improvements (https://forums.graalonline.com/forums/forumdisplay.php?f=10)
-   -   Dynamic Functions Thing (https://forums.graalonline.com/forums/showthread.php?t=134262681)

fowlplay4 04-04-2011 03:07 AM

Dynamic Functions Thing
 
I'm not sure what the correct term is but here's what I think would be cool to have...

PHP Code:

function onCreated() {
  
this.testfunc = function () {
    return 
"Hello World";
  };
  echo(
this.testfunc); // should echo "Hello World"
} 

However instead it echos: "function_xxxxxxx_yyyy"

Calling the function instead of returning the name would be so much more useful and fun.

Tolnaftate2004 04-04-2011 03:32 AM

Quote:

Originally Posted by fowlplay4 (Post 1641100)
Calling the function instead of returning the name would be so much more useful and fun.

PHP Code:

echo(temp.testfunc()); 

?

fowlplay4 04-04-2011 03:50 AM

Quote:

Originally Posted by Tolnaftate2004 (Post 1641105)
PHP Code:

echo(temp.testfunc()); 

?

Sure I could use ()'s and just call the function that way, just thought it would be cool for it to call the function instead of returning the 'name' of it instead.

cbk1994 04-04-2011 03:53 AM

Would be kind of nice since you could use it just like a variable. It would make it easy to have options that you could have a function for or a constant variable.

WhiteDragon 04-04-2011 05:28 AM

No, this is wrong.

Having a constant function automatically be evaluated when coerced to a string doesn't reflect the reality and also provides some more confusion for anyone trying to learn.

Functions are functions, functions are values, but functions are not fully-evaluated values. Anything suggesting otherwise will be misleading.

fowlplay4 04-04-2011 05:56 AM

Quote:

Originally Posted by WhiteDragon (Post 1641123)
also provides some more confusion for anyone trying to learn.

Right :(


All times are GMT +2. The time now is 02:39 AM.

Powered by vBulletin® Version 3.8.11
Copyright ©2000 - 2026, vBulletin Solutions Inc.
Copyright (C) 1998-2019 Toonslab All Rights Reserved.