Skip to content

Instantly share code, notes, and snippets.

@monjer
Last active December 18, 2015 07:58
Show Gist options
  • Select an option

  • Save monjer/787f98373b7a5bc4d85e to your computer and use it in GitHub Desktop.

Select an option

Save monjer/787f98373b7a5bc4d85e to your computer and use it in GitHub Desktop.
使用jQuery的自定义事件机制实现消息中心
(function($){
var $d = $({});
var Dispatcher = {
on:function(event , callback , ctx){
var proxy = $.proxy(callback , ctx);
$d.on(event,proxy);
},
once:function(event , callback , ctx){
var proxy = $.proxy(callback , ctx);
$d.one(event,proxy);
},
off:function(event , callback ){
$d.off(event , callback);
},
trigger:function(event){
$d.trigger(event , [].slice.call(arguments , 1) );
}
}
window.Dispatcher = Dispatcher ;
})(jQuery)
@monjer

monjer commented Nov 3, 2015

Copy link
Copy Markdown
Author

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment