調査アンケート: Blockly のご利用体験についてお聞かせください
アンケートを開始
コレクションでコンテンツを整理
必要に応じて、コンテンツの保存と分類を行います。
ブロックする >CodeGenerator >provideFunction_
CodeGenerator.provideFunction_() メソッド
生成されたコードに含めるデベロッパー定義の関数(ユーザー定義プロシージャではない)を定義します。プライベート ヘルパー関数の作成に使用されます。指定された requiredName でこれを初めて呼び出すと、コードが保存され、実際の名前が生成されます。同じ requestedName を持つ後続の呼び出しは効果がありませんが、戻り値は同じになります。
異なるヘルパー関数で同じ dependsName を使用しないようにするかどうかは、呼び出し元によって異なります(たとえば、「random」ではなく「colourRandom」と「listRandom」を使用)。予約語、ユーザー定義変数、プロシージャ名と競合する危険はありません。
CodeGenerator.finish() が呼び出されると、コードが出力されます。
署名:
provideFunction_(desiredName: string, code: string[] | string): string;
パラメータ
パラメータ |
型 |
説明 |
desiredName |
文字列 |
関数の任意の名前(例: mathIsPrime)。 |
コード |
string[] |文字列 |
ステートメントのリストまたは 1 つの複数行のコード文字列。'」を使用します(置換されます)。 |
戻り値:
文字列
新しい関数の実際の名前。ユーザーがすでに取得している場合は、dressdName と異なることがあります。
特に記載のない限り、このページのコンテンツはクリエイティブ・コモンズの表示 4.0 ライセンスにより使用許諾されます。コードサンプルは Apache 2.0 ライセンスにより使用許諾されます。詳しくは、Google Developers サイトのポリシーをご覧ください。Java は Oracle および関連会社の登録商標です。
最終更新日 2024-08-21 UTC。
[[["わかりやすい","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 UTC。"],[[["`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"]]