透過集合功能整理內容
你可以依據偏好儲存及分類內容。
封鎖 >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 (世界標準時間)。
[[["容易理解","easyToUnderstand","thumb-up"],["確實解決了我的問題","solvedMyProblem","thumb-up"],["其他","otherUp","thumb-up"]],[["缺少我需要的資訊","missingTheInformationINeed","thumb-down"],["過於複雜/步驟過多","tooComplicatedTooManySteps","thumb-down"],["過時","outOfDate","thumb-down"],["翻譯問題","translationIssue","thumb-down"],["示例/程式碼問題","samplesCodeIssue","thumb-down"],["其他","otherDown","thumb-down"]],["上次更新時間: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."]]],["The `provideFunction_()` method defines developer-created helper functions for generated code. It takes a `desiredName` and `code` (string or string array). The first call with a `desiredName` saves the `code` and generates a function name. Subsequent calls with the same `desiredName` are ignored. The function name is returned, and may differ from `desiredName` if a name conflict is detected. The code is output when `CodeGenerator.finish()` is called. The method is used to prevent name collisions with user-defined items.\n"]]