แบบสำรวจการวิจัย: บอกให้เราทราบเกี่ยวกับประสบการณ์การใช้งาน Blockly
เริ่มแบบสำรวจ
จัดทุกอย่างให้เป็นระเบียบอยู่เสมอด้วยคอลเล็กชัน
บันทึกและจัดหมวดหมู่เนื้อหาตามค่ากำหนดของคุณ
blockly > CodeGenerator > provideFunction_
เมธอด CodeGenerator.servingFunction_()
กำหนดฟังก์ชันที่นักพัฒนาซอฟต์แวร์กำหนด (ไม่ใช่ขั้นตอนที่ผู้ใช้กำหนด) ที่จะรวมอยู่ในโค้ดที่สร้างขึ้น ใช้สำหรับสร้างฟังก์ชันผู้ช่วยส่วนตัว ครั้งแรกที่มีการเรียกชื่อที่ต้องการ ชื่อที่ต้องการจะได้รับการบันทึกโค้ดและสร้างชื่อจริงขึ้นมา การเรียกครั้งต่อๆ ไปที่มี PreferredName เดียวกันจะไม่มีผลใดๆ แต่จะมีมูลค่าผลลัพธ์เหมือนกัน
ผู้โทรจะตรวจสอบว่าไม่ได้มีการใช้ PreferredName เดียวกันสำหรับฟังก์ชันตัวช่วยที่แตกต่างกัน (เช่น ใช้ "colourRandom" และ "listRandom" ไม่ใช่ "random") ไม่มีอันตรายของการชนกับคำที่สงวนไว้ หรือชื่อตัวแปรหรือชื่อกระบวนการที่ผู้ใช้กำหนด
โค้ดจะได้รับเอาต์พุตเมื่อมีการเรียกใช้ CodeGenerator.finish()
ลายเซ็น:
provideFunction_(desiredName: string, code: string[] | string): string;
พารามิเตอร์
พารามิเตอร์ |
ประเภท |
คำอธิบาย |
desiredName |
สตริง |
ชื่อฟังก์ชันที่ต้องการ (เช่น mathIsPrime) |
รหัส |
สตริง[] | สตริง |
รายการคำสั่งหรือสตริงโค้ดหลายบรรทัด 1 รายการ ใช้ " " สำหรับการเยื้อง (จะถูกแทนที่) |
การคืนสินค้า:
สตริง
ชื่อจริงของฟังก์ชันใหม่ ซึ่งอาจแตกต่างจาก PreferredName หากผู้ใช้ได้ใช้ชื่อเดิมไปแล้ว
เนื้อหาของหน้าเว็บนี้ได้รับอนุญาตภายใต้ใบอนุญาตที่ต้องระบุที่มาของครีเอทีฟคอมมอนส์ 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"]]