Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > HTML > JavaScript: conditionally invoking functions within a function

Reply
Thread Tools

JavaScript: conditionally invoking functions within a function

 
 
Spartanicus
Guest
Posts: n/a
 
      09-30-2005
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

--
Spartanicus
 
Reply With Quote
 
 
 
 
Oli Filth
Guest
Posts: n/a
 
      09-30-2005
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.
> }
> }
>



--
Oli
 
Reply With Quote
 
 
 
 
Neredbojias
Guest
Posts: n/a
 
      09-30-2005
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();
}
}

--
Neredbojias
Contrary to popular belief, it is believable.
 
Reply With Quote
 
Spartanicus
Guest
Posts: n/a
 
      09-30-2005
Oli Filth <(E-Mail Removed)> wrote:

>> How should functions be invoked conditionally from within a function?
>> This throws errors and doesn't work:


>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.

--
Spartanicus
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Invoking c function in a c plus plus function... Rahul C++ 9 03-25-2008 05:24 PM
conditionally creating functions within a class? kaens Python 1 05-26-2007 09:19 AM
Conditionally display image within FormView Mike ASP .Net 1 12-31-2006 08:43 AM
Using variadic functions within variadic functions pinkfloydhomer@gmail.com C Programming 2 02-27-2006 05:47 AM
Execute a function in each element of the list conditionally Teddy.Gammell@gmail.com C++ 6 01-19-2006 09:39 PM



Advertisments