官术网_书友最值得收藏!

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.

主站蜘蛛池模板: 海兴县| 松桃| 无锡市| 石阡县| 延长县| 壤塘县| 西华县| 肥西县| 积石山| 英山县| 漯河市| 车致| 嵩明县| 杨浦区| 陕西省| 吉林市| 祁阳县| 丰原市| 仁布县| 东乌珠穆沁旗| 肇源县| 祥云县| 兰西县| 进贤县| 海阳市| 宜宾市| 蚌埠市| 湖口县| 佛冈县| 晋州市| 六安市| 临高县| 玛多县| 鸡泽县| 咸阳市| 师宗县| 宁南县| 和田县| 大悟县| 朔州市| 旬阳县|