Asp-Classic
從經典 ASP 中的函式提前返回
有沒有辦法從經典 ASP 中的函式提前返回而不是執行函式的全部長度?例如,假設我有這個功能……
Function MyFunc(str) if (str = "ReturnNow!") then Response.Write("What up!") else Response.Write("Made it to the end") end if End Function我可以這樣寫嗎…
Function MyFunc(str) if (str = "ReturnNow!") then Response.Write("What up!") return end if Response.Write("Made it to the end") End Function請注意我在經典 ASP 中當然不能執行的 return 語句。有沒有辦法在返回語句所在的位置中斷程式碼執行?
是的,使用
exit function.Function MyFunc(str) if str = "ReturnNow!" then Response.Write("What up!") Exit Function end if Response.Write("Made it to the end") End Function我通常在從函式返回值時使用它。
Function usefulFunc(str) ''# Validate Input If str = "" Then usefulFunc = "" Exit Function End If ''# Real function ''# ... End Function