このようなコードがあります。このコードは機能しますが、ひどいように見えます。
if(typeof(d.object) != "undefined"){
if(typeof(d.object.property) != "undefined"){
if(typeof(d.object.property.length) != "undefined"){
// do the code
}
else alert("error");
}
else alert("error");
}
else alert("error");
これを書き直して同じように、しかしより効率的にする方法はありますか?特にエラーはすべて同じだからです。