예, 괜찮습니다. 재귀를 할 때마다 (a) 기본 사례와 (b) 재귀 사례가 있어야합니다.
두 번째 경우에만 함수가 자체적으로 함수를 호출하므로 기본 case에 없는지 확인하십시오. 그렇지 않으면 무한 재귀가 발생합니다. 예를 들어,이 계승 기능 0 기본 경우와, 다른 모든 대안 재귀 경우
function fact(n) {
if (n==0) { return 1; }
else { return n * factorial(n-1) }
}
, 당신은 즉, 한 번에 하나씩 할 수 있습니다. 첫 번째로드를 시작하기 전에 하나가 완전히로드 될 때까지 기다릴 필요없이 첫 번째로드를 시작한 다음 두 번째로드를 시작하십시오. 나는 구글이 API 피드 모르는
// 'feeds' is an array of the feed URLs
function grabFeeds(feeds) {
var index;
// We start with the first feed
index = 0;
// Kick off the process
feedWorker();
// Our "go get the next feed" function
function feedWorker() {
var feed;
// Do we have any more?
if (index < feeds.length) {
// Yes, request it and bump our index
// (You could combine these lines, but it's
// clearer to keep them separate)
feed = feeds[index];
++index;
start_feed_download(feed, callback);
}
}
// Our callback function
function callback() {
// ...do something with the result...
// Kick of the next feed (feedWorker is defensive,
// so we don't have to check index here)
feedWorker();
}
}
, 따라서 자리 start_feed_download
기능 : 당신이 그것을 할 수있는 방법
감사합니다. 폐쇄에 대한 추가 설명 주셔서 감사합니다. 그것에 지금 읽는. – Jan