我找不到示例。我如何爲我的PowerShell功能製作原型?如何在PowerShell中創建函數原型?
function exampleFunc(); //other stuff that calls the example function Function exampleFunc(){//stuff}
我找不到示例。我如何爲我的PowerShell功能製作原型?如何在PowerShell中創建函數原型?
function exampleFunc(); //other stuff that calls the example function Function exampleFunc(){//stuff}
你可以要求通過快速按鈕按Ctrl + J通過右鍵點擊或訪問從PowerShell的ISE(集成Scription環境)片段。
PowerShell不支持原型函數,轉發聲明或您希望用於此的任何術語。在PowerShell中,當您使用function
關鍵字時,您正在定義一個函數。如果使用相同的函數名稱調用它兩次,則更改該函數的定義。
This question大約與bash相同的問題列出瞭解決該問題的常見方法。您可以在PowerShell中執行相同的操作。
另一種選擇是使用Begin {} Process {} End {}
高級函數構造,並將所有函數聲明放入Begin {}
部分。
這裏是@培根位代碼將是什麼樣子
function main()
{
cls
Begin
Process
End
}
function Begin {
}
function Process {
}
function End {
}
main
上有[SO文檔(http://stackoverflow.com/documentation/powershell/1673/powershell-functions#例子t = 201607281323139314936) – 4castle
我的意思是像 '功能exampleFunc();' '其他東西,調用示例函數' '函數exampleFunc(){//東西}' –
你不能這樣做。 Powershell不是一種編譯語言。 – 4castle