- jQuery Design Patterns
- Thodoris Greasidis
- 132字
- 2021-07-16 12:52:28
Using custom event namespacing
As a closing note for this chapter, we will present, in short, the mechanism that jQuery provides for namespacing custom events. The main benefit of event namespacing is that it allows us to use more specific event names that better describe their purpose, while also helping us to avoid conflicts between different implementation parts and plugins. It also provides a convenient way to unbind all the events of a given namespace from any target (element or broker).
A simple example implementation will look as follows:
var broker = $({}); broker.on('close.dialog', function (event, message){ console.log(event.type, event.namespace); }); broker.trigger('close.dialog', ['messageEmitted']); broker.off('.dialog'); // removes all event handlers of the "dialog" namespace
For more information, you can visit the documentation page at http://docs.jquery.com/Namespaced_Events and the article at https://css-tricks.com/namespaced-events-jquery/ from the CSS-Tricks website.
推薦閱讀
- 大學計算機基礎(chǔ)實驗教程
- JMeter 性能測試實戰(zhàn)(第2版)
- 基于Java技術(shù)的Web應用開發(fā)
- Blender 3D Incredible Machines
- 編程數(shù)學
- 深入理解Android:Wi-Fi、NFC和GPS卷
- Swift細致入門與最佳實踐
- Python編程從0到1(視頻教學版)
- Windows Embedded CE 6.0程序設(shè)計實戰(zhàn)
- Python網(wǎng)絡(luò)爬蟲技術(shù)與應用
- Everyday Data Structures
- MongoDB Cookbook
- Web開發(fā)新體驗
- HTML5程序開發(fā)范例寶典
- Hands-On Data Visualization with Bokeh