How do I restart a function calling it from inside the same function?
Just call the function again, then return, like this:
function myFunction() {
//stuff...
if(condition) {
myFunction();
return;
}
}
The if
part is optional of course, I'm not certain of your exact application here. If you need the return value, it's one line, like this: return myFunction();
Well its recommended to use a named function now instead of arguments.callee which is still valid, but seemingly deprecated in the future.
// Named function approach
function myFunction() {
// Call again
myFunction();
}
// Anonymous function using the future deprecated arguments.callee
(function() {
// Call again
arguments.callee();
)();
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With