3
よく私が見(そして時には書き込み)のようなコード:JavaScriptで `return cb()`に不利な点はありますか?
var foo = function(someOption, cb){
// handle some edge case where we don't need to do anything
if (someOption === 'whatever') {
return cb(null)
}
...do things...
cb(result)
}
いうより:関数の戻り値が使用されていない
var foo = function(someOption, cb){
// handle some edge case where we don't need to do anything
if (someOption === 'whatever') {
cb(null)
return;
}
...do things...
cb(result)
}
、return
だけで、早期の機能を終了。
いずれのアプローチのデメリットや利点はありますか?
最初は何も
return
を返さないのに対し、は、私は戻り値は便利なものだと思います。 – PeeHaa
あなたが関数cbの戻り値を使用したい場合、その必要がありますが、実装を見た後では、その値を使用しないようです –