Created
January 7, 2017 19:01
-
-
Save poga/e52c5eeec4dba6f91a149b4a71047dea to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// before | |
// 通常這四個都有個共通的因素,才會被擺在一起 | |
if (rtn == RESULT_A || rtn == RESULT_B || rtn == RESULT_C || rtn == RESULT_D) { | |
Do1(); | |
} else { | |
Do2(); | |
} | |
// after | |
// 所以就把那個因素寫成 function name | |
function someReason(rtn) { | |
return rtn == RESULT_A || rtn == RESULT_B || rtn == RESULT_C || rtn == RESULT_D | |
} | |
// 這樣就可以直接理解因素是什麼,而不用看實做細節 | |
if (someReason(rtn)) { | |
Do1(); | |
} else { | |
Do2(); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
好妙啊(反覆咀嚼