in**@baseportal.de wrote in comp.lang.javascript
:
Hi...
I want to know (inside a function) if the calling code wants a return
value or not.
You probably mean to say if the calling code can expect a return value to
the called function.
>
Here is an example:
function foo()
{
alert(return_wanted()); // "return_wanted" is just a name of the
function I search...
}
x=foo();
Since foo() returns no value, 'x' should be undefined.
>
foo();
which should give "true" in the first case and "false" in the second.
You mean to assign a value TRUE and FALSE? To what?
The function alert() is technically not defined in Javascript core.
An according function in perl is called "wantarray", which gives
"undef" if no return value is wanted.
Is there anything like this in javascript?
Should you want to evaluate the status of an identifier (a name for a
variable or function or object), use the typeof() operator, which returns
a string describing what you probably want. This might be especially
useful if the identifier is a variable used to hold the return value of a
called function, if there is one.