function-expression

Calling a javascript function recursively

北城余情 提交于 2019-11-26 03:47:56
问题 I can create a recursive function in a variable like so: /* Count down to 0 recursively. */ var functionHolder = function (counter) { output(counter); if (counter > 0) { functionHolder(counter-1); } } With this, functionHolder(3); would output 3 2 1 0 . Let\'s say I did the following: var copyFunction = functionHolder; copyFunction(3); would output 3 2 1 0 as above. If I then changed functionHolder as follows: functionHolder = function(whatever) { output(\"Stop counting!\"); Then