ui.util.debounce
จัดทุกอย่างให้เป็นระเบียบอยู่เสมอด้วยคอลเล็กชัน
บันทึกและจัดหมวดหมู่เนื้อหาตามค่ากำหนดของคุณ
รวมฟังก์ชันเพื่อให้เรียกใช้ได้สูงสุด 1 ครั้งสำหรับลำดับการเรียกใช้แต่ละลำดับที่เริ่มทำงานซ้ำๆ ตราบใดที่การเรียกใช้แต่ละครั้งอยู่ห่างกันน้อยกว่าช่วงเวลาที่ระบุ (เป็นมิลลิวินาที) ซึ่งใช้เพื่อลดจำนวนการเรียกใช้ฟังก์ชันที่มีค่าใช้จ่ายสูงได้ในขณะที่ยังคงมั่นใจได้ว่าฟังก์ชันจะทำงานในที่สุด
ตัวอย่างการใช้งาน: สำหรับ Callback ของเหตุการณ์การเปลี่ยนแปลงใน ui.Checkbox หากผู้ใช้คลิกช่องทําเครื่องหมายซ้ำๆ ระบบจะเรียกใช้การเรียกกลับเฉพาะการคลิกครั้งสุดท้ายของช่องทําเครื่องหมาย
แสดงผลฟังก์ชันที่ลดการดีบาวซ์
การใช้งาน | การคืนสินค้า |
---|
ui.util.debounce(func, delay, scope) | ฟังก์ชัน |
อาร์กิวเมนต์ | ประเภท | รายละเอียด |
---|
func | ฟังก์ชัน | ฟังก์ชันที่จะดีบาวซ์ |
delay | ตัวเลข | หลังจากเรียกฟังก์ชันแล้ว 1 ครั้ง จำนวนมิลลิวินาทีที่จะหน่วงเวลาสำหรับการเรียกใช้ฟังก์ชันเพิ่มเติมก่อนที่จะอนุญาตให้เรียกใช้ |
scope | ออบเจ็กต์ (ไม่บังคับ) | ออบเจ็กต์ในขอบเขตที่จะเรียกใช้ฟังก์ชัน |
เนื้อหาของหน้าเว็บนี้ได้รับอนุญาตภายใต้ใบอนุญาตที่ต้องระบุที่มาของครีเอทีฟคอมมอนส์ 4.0 และตัวอย่างโค้ดได้รับอนุญาตภายใต้ใบอนุญาต Apache 2.0 เว้นแต่จะระบุไว้เป็นอย่างอื่น โปรดดูรายละเอียดที่นโยบายเว็บไซต์ Google Developers Java เป็นเครื่องหมายการค้าจดทะเบียนของ Oracle และ/หรือบริษัทในเครือ
อัปเดตล่าสุด 2025-07-26 UTC
[null,null,["อัปเดตล่าสุด 2025-07-26 UTC"],[[["\u003cp\u003eDebounces a function, limiting its execution to at most once within a specified time interval, even with repeated calls.\u003c/p\u003e\n"],["\u003cp\u003eUseful for optimizing expensive functions triggered by frequent events, ensuring only the last call within the interval is executed.\u003c/p\u003e\n"],["\u003cp\u003eReturns a debounced version of the original function, which can be called directly.\u003c/p\u003e\n"],["\u003cp\u003eCustomizable with parameters like \u003ccode\u003edelay\u003c/code\u003e for setting the debounce interval and \u003ccode\u003escope\u003c/code\u003e for controlling the function's execution context.\u003c/p\u003e\n"]]],[],null,["# ui.util.debounce\n\n\u003cbr /\u003e\n\nWraps a function to allow it to be called, at most, once for each sequence of calls fired repeatedly so long as they are fired less than a specified interval apart (in milliseconds). This can be used to reduce the number of invocations of an expensive function while ensuring it eventually runs.\n\n\u003cbr /\u003e\n\nExample use: For the callback to a change event on a ui.Checkbox. If the user clicks the checkbox repeatedly, only the last click of the checkbox will run the callback.\n\nReturns the debounced function.\n\n| Usage | Returns |\n|--------------------------------------------|----------|\n| `ui.util.debounce(func, delay, `*scope*`)` | Function |\n\n| Argument | Type | Details |\n|----------|------------------|------------------------------------------------------------------------------------------------------------------------------------------------|\n| `func` | Function | The function to debounce. |\n| `delay` | Number | After the function is called once, the number of milliseconds to delay for an additional invocation of the function before allowing it to run. |\n| `scope` | Object, optional | Object in whose scope to call the function. |"]]