סקר מחקר: נשמח לשמוע על החוויה שלך עם Blockly
לפתיחת הסקר
blockly > CodeGenerator > provideFunction_
שיטת CodeGenerator.providerFunction_()
מגדירים פונקציה בהגדרת המפתח (לא תהליך שמוגדר על ידי המשתמש) שתיכלל בקוד שנוצר. משמש ליצירת פונקציות עזר פרטיות. בפעם הראשונה שבה קוראים למחרוזת הזו עם שם רצוי מסוים, הקוד נשמר ונוצר שם אמיתי. לשיחות הבאות אין השפעה זהה, אבל יש להן ערך מוחזר זהה.
מבצע הקריאה החוזרת הוא לוודא שאותו מיקום רצוי לא משמש לפונקציות סיוע שונות (למשל: להשתמש ב-"colorRandom" וב-"listRandom", ולא ב"אקראי"). אין סכנה להתנגשות עם מילים שמורות או עם שמות של משתנים או הנהלים שמוגדרים על ידי המשתמש.
הקוד מקבל פלט כשמתבצעת קריאה ל-CodeGenerator.fi ספציפיות() .
Signature:
provideFunction_(desiredName: string, code: string[] | string): string;
פרמטרים
פרמטר |
סוג |
תיאור |
desiredName |
מחרוזת |
השם הרצוי של הפונקציה (למשל, MatIsPrime). |
קוד |
string[] | String (מחרוזת) |
רשימה של הצהרות או מחרוזת קוד אחת עם מספר שורות. שימוש ב-' ' לכניסות פסקה (הם יוחלפו). |
החזרות:
מחרוזת
השם בפועל של הפונקציה החדשה. יכול להיות שהשם הזה יהיה שונה מהשם הרצוי אם השם הקודם כבר נתפס על ידי המשתמש.
אלא אם צוין אחרת, התוכן של דף זה הוא ברישיון Creative Commons Attribution 4.0 ודוגמאות הקוד הן ברישיון Apache 2.0. לפרטים, ניתן לעיין במדיניות האתר Google Developers. Java הוא סימן מסחרי רשום של חברת Oracle ו/או של השותפים העצמאיים שלה.
עדכון אחרון: 2024-08-21 (שעון UTC).
[null,null,["עדכון אחרון: 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"]]