|
|
|
If a callback calls the enclosing function, would it be called a recursive call?
|
|
2 points
by anuragpeshne
4170 days ago
|
|
I asked this question[1] on stackoverflow but could not get any convincing answer: http.request(options, function(res) {
res.on('data', function(chunk) {
data+=chunk;
}); res.on('end', function(){
//do some stuff
http.request(options, function(res) {...});//is this recursive?
});
}).end();Or a simpler case:
suppose there is a function which reads a file character by character: var noOfChar = 10;
var i = 0;
readChar(function processChar(char){
if(i < noOfChar) {
console.log(char);
i++;
readChar(processChar); //is this recursive?
}
} |
|
1. Why does it matter?
2. Your first example I would simply call an asynchronous loop.
3. Your second example could possibly be called single recursion.
4. Recursion should at least consist of a base case and a recursive case, each self-reference should bring the input value closer to the base case which would end the recursion.
(Your second example has a recursive case and falls out into an undefined base case).
5. An example of 4 would be a tree structure where the base case is a leaf and recursion cases are branches.
would output: 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14