Home Articles FAQs XREF Games Software Instant Books About Feedback Search Site-Map
irt.org logo

Q1272 Can I invoke a function with parameters using setTimeout?

irt.org | Knowledge Base | JavaScript | Timeout | Q1272 [ previous next ]

Q1272 Can I invoke a function with parameters using setTimeout?

The setTimeout method takes an expression to be evaluted after the interval has expired. The expression is commonly used by way of a string - but it doesn't have to be - it can be anything that evaluates to some string that can then be passed to the setTimeout method.

So if we use:

setTimeout(functionA(parms),7000);
//--></script>

It executes functionB() now! Passing the parms to functionB() now! And then passes its result as input to the setTimeout method which is then evaluted in 7 seconds time.

Note: if the functionA() returns nothing then the JavaScript code will throw an error.

If using:

setTimeout('functionA(parms)',7000);
//--></script>

We pass a string 'funtionB(parms)' as input to the setTimeout method which is evaluated in 7 seconds time. If parms no longer have scope within this context, or functionA() no longer exists then an error occurs.

Feedback on 'Q1272 Can I invoke a function with parameters using setTimeout?'


Provide feedback ...
AddThis Social Bookmark Button

Provide feedback ... AddThis Social Bookmark Button


Last Updated: 30th March 2008. Maintained by: Martin Webb and Michel Plungjan
irt.org liability, trademark, document use, privacy statement and software licensing rules apply.
Copyright © 1996-2008 irt.org, All Rights Reserved.