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

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.

主站蜘蛛池模板: 韶山市| 遂溪县| 板桥市| 神农架林区| 巴林左旗| 滦南县| 周至县| 且末县| 西乌珠穆沁旗| 乐平市| 桂平市| 澄城县| 寻乌县| 永德县| 巨鹿县| 云阳县| 闽清县| 正镶白旗| 罗甸县| 岳池县| 项城市| 金门县| 灵寿县| 江达县| 墨竹工卡县| 凤阳县| 卢氏县| 晋州市| 大理市| 芷江| 肇庆市| 青田县| 石门县| 大石桥市| 茶陵县| 尉氏县| 乌海市| 尉犁县| 眉山市| 铁岭县| 神池县|