0
我有一些(我認爲他們可能很愚蠢)的問題......但他們是問題,我想在這裏發帖,然後進行辯論。關於JavaScript中的條件問題
這是關於條件。我正在開發JavaScript,並且我有一些功能,並且我希望編寫最佳代碼。
例如,我要檢查一些條件,因此我可以這樣寫:
if(text == ""){
//some code for finish
}else if(text== previousText){
//some code for finish
}
//here I write more code...which runs if both conditions had not complied.
我的疑問是:你覺得什麼是好做?
1點
if(text == ""){
//some code for finish
}else if(text== previousText){
//some code for finish
}else{
//here I write more code...which runs if both conditions had not complied.
}
或
點2
if(text == ""){
//some code for finish using return
return;
}else if(text== previousText){
//some code for finish using return
return;
}
//here I write more code...which runs if both conditions had not complied.
我希望已經解釋好。有時候這些東西沒有被注意到,但我認爲它們很重要。 非常感謝,丹尼爾
我的建議是不要過度去想這樣的事情,你永遠不會做任何事情。只要代碼有效並且可讀,就沒有問題。 – Dunhamzzz 2013-02-12 15:16:13
這是所有意見的問題。就個人而言,我不喜歡函數或方法中的多個返回語句,但有些可以。我不會說一個人一定比另一個好。 – marteljn 2013-02-12 15:16:39
好吧,我明白了...謝謝 – 2013-02-12 15:17:19