6

node.js async パッケージ、具体的には forEachSeries を使用して、配列から引き出されたパラメーターに基づいて一連の http 要求を作成しています。各リクエストのコールバックには、さまざまなタイプのレスポンスに応答するための if/else ステートメントがあります。

// This is the callback of a GET request inside of a forEachSeries
function(error, response) {
    if (response.results) {
        // Do something with results
    }
    else if (!response.results) {
        // Would like to use a continue statement here, but
        // this is not inside of a loop
    }
    else {
        // Do something else
    }
}

上記のelse ifの中で使用できる「continue」に相当するものはありますか? これは技術的にはループ内ではないため、続行は機能しません。

4

1 に答える 1

6

returnそれは単なる関数であるため、同じ効果を得るためにそれからできるはずです:

else if (!response.results) {
    return;
}
于 2012-04-11T13:21:46.417 に答える