- 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.
推薦閱讀
- UI圖標(biāo)創(chuàng)意設(shè)計(jì)
- .NET 4.0面向?qū)ο缶幊搪劊夯A(chǔ)篇
- SQL基礎(chǔ)教程(視頻教學(xué)版)
- SQL經(jīng)典實(shí)例(第2版)
- 精通MATLAB(第3版)
- BIM概論及Revit精講
- Tableau 10 Bootcamp
- QPanda量子計(jì)算編程
- NGUI for Unity
- Socket.IO Cookbook
- C語(yǔ)言從入門(mén)到精通(視頻實(shí)戰(zhàn)版)
- Java核心技術(shù)速學(xué)版(第3版)
- 少年小魚(yú)的魔法之旅:神奇的Python
- JavaScript全棧開(kāi)發(fā)
- Modern R Programming Cookbook