get info about return value for a function is wanted or not?

I

info

Hi...

I want to know (inside a function) if the calling code wants a return
value or not.

Here is an example:


function foo()
{
alert(return_wanted()); // "return_wanted" is just a name of the
function I search...
}

x=foo();

foo();


which should give "true" in the first case and "false" in the second.

An according function in perl is called "wantarray", which gives
"undef" if no return value is wanted.

Is there anything like this in javascript?

Thanks for any help in advance,

Christoph Bergmann
 
P

Patient Guy

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.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,770
Messages
2,569,583
Members
45,075
Latest member
MakersCBDBloodSupport

Latest Threads

Top