|
|
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:
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:
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?' |
-- div -->
|