JavaScript: conditionally invoking functions within a function

O

Oli Filth

Spartanicus said the following on 30/09/2005 14:15:
How should functions be invoked conditionally from within a function?
This throws errors and doesn't work:

function test() {
if (0 == 0)
{
function foo();
^
^
You don't need "function" here.
}
if (1 == 1)
{
function bar();
^
^
Nor here.
 
N

Neredbojias

With neither quill nor qualm, Spartanicus quothed:
How should functions be invoked conditionally from within a function?
This throws errors and doesn't work:

function test() {
if (0 == 0)
{
function foo();
}
if (1 == 1)
{
function bar();
}
}

Minimized test case: http://homepage.ntlworld.com/spartanicus/temp.htm

You've basically got it right.

function test() {
if (a) {
foo();
} else {
if (b) bar();
}
}
 
S

Spartanicus

You don't need "function" here.

That's the second time that I coded an error in the minimized example
that wasn't in the actual code. Fortunately I've now pinned down the
cause of the trouble with the actual script, thanks for your help.
 

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

No members online now.

Forum statistics

Threads
473,768
Messages
2,569,574
Members
45,051
Latest member
CarleyMcCr

Latest Threads

Top