我有許多功能(funcOne, funcTwo, etc.
),所有的人都在開始(我想那些塊移動到一個單獨的函數或東西,所以我不重複的代碼共享檢查相同的塊,但問題是,我使用的回報。請仔細閱讀)清洗重複使用返回代碼
- 如果這些檢查失敗,我輸出特定的消息,這個特定的檢查失敗,並返回(因此函數的實際代碼不執行)
- 如果所有的檢查通過,則功能繼續功能的特定代碼。
我想要做的是移動的檢查,以一個單獨的函數。但問題是,我使用return;
這將返回出來的新功能,但不會從funcOne and funcTwo
返回。有人可以幫助我重構此代碼,因此我不必在使用它們的每個函數中重複執行重複檢查。
protected function funcOne(event:MouseEvent):void { if(check 1 doesn't pass){ Alert.show("error 1, returning); return; } if(check 2 doesn't pass){ Alert.show("error 2, returning); return; } .... more checks here, all of them return specific messages //if all checks pass //execute the specific code of this funcOne } protected function funcTwo(event:MouseEvent):void { if(check 1 doesn't pass){ Alert.show("error 1, returning); return; } if(check 2 doesn't pass){ Alert.show("error 2, returning); return; } .... more checks here, all of them return specific messages //if all checks pass //execute the specific code of this funcTwo }
必須要麼讓「驗證」一個getter,這樣就可以把它叫做沒有括號或在每次調用寫括號。否則,你會檢查參考的價值,因爲你的功能是「硬編碼」,而不是動態的設置將始終返回true。所以你的例子不完整。 – LoremIpsum
該死的,我完全忘了括號!我不想讓它變成一個吸氣器,不會有多大的意義。我編輯了我的帖子,對於錯誤感到抱歉。 – Exort
我的意思是括號,而不是大括號。 – LoremIpsum