封鎖 >CodeGenerator >provideFunction_
CodeGenerator.ProvideFunction_() 方法
定義要在產生的程式碼中納入的開發人員定義函式 (而非使用者定義程序)。用於建立私人輔助函式。初次使用指定的 actionName 呼叫此方法時,系統會儲存程式碼並產生實際名稱。後續呼叫同一個 goalName 的後續呼叫不會產生任何作用,但傳回值相同。
呼叫端應自行確認相同的 requiredName 並未用於不同的輔助函式 (例如,使用「colourRandom」和「listRandom」,而非「random」)。保留字詞、使用者定義的變數或程序名稱不會發生衝突。
呼叫 CodeGenerator.finish() 時,程式碼會取得輸出內容。
Signature:
provideFunction_(desiredName: string, code: string[] | string): string;
參數
參數 |
類型 |
說明 |
desiredName |
字串 |
所需的函式名稱 (例如 mathIsPrime)。 |
程式碼 |
string[] |字串 |
陳述式清單或多行程式碼字串的清單。使用「」,即可取代縮排。 |
傳回:
字串
新函式的實際名稱。如果使用者已採用 userName,則這可能與 requirementsName 不同。
除非另有註明,否則本頁面中的內容是採用創用 CC 姓名標示 4.0 授權,程式碼範例則為阿帕契 2.0 授權。詳情請參閱《Google Developers 網站政策》。Java 是 Oracle 和/或其關聯企業的註冊商標。
上次更新時間:2024-08-21 (世界標準時間)。
[null,null,["上次更新時間:2024-08-21 (世界標準時間)。"],[[["`CodeGenerator.provideFunction_()` defines developer-defined helper functions for inclusion in the generated code, assigning a unique name to avoid conflicts."],["Calling this method multiple times with the same `desiredName` has no effect but returns the previously assigned unique name."],["Generated helper function code is output when `CodeGenerator.finish()` is called."],["The method takes the desired function name and code as input, returning the actual assigned function name."],["Ensure distinct `desiredName` values for different helper functions to prevent unintended behavior."]]],[]]