Difference Between Countup() And Countup
I have a script that counts up the number in a box (actually, in this exercise -> http://jqexercise.droppages.com/#page_0022_ ) each 1 second like this. var target = $('#target
Solution 1:
countUp
references the function as an object. In JavaScript everything is an object, including functions, and can be passed around. countUp()
calls the function countUp
and returns its value.
Solution 2:
Adding the ()
to the function invokes it instantly, while just using the function name is actually passing it as a parameter.
Solution 3:
countUp()
is a recursive invocation of the function. Each call to the function invokes it again (immediately), and the return value (which is undefined
) is passed to setTimeout.
This would be an infinite loop, except I believe the exception from setTimeout
receiving a non function is interrupting it after 1 second, leading to a stop at 15616.
Post a Comment for "Difference Between Countup() And Countup"