Skip to content

Instantly share code, notes, and snippets.

@creamidea
Forked from cowboy/HEY-YOU.md
Created December 17, 2012 14:00
Show Gist options
  • Save creamidea/4318472 to your computer and use it in GitHub Desktop.
Save creamidea/4318472 to your computer and use it in GitHub Desktop.
这是一个用js实现的订阅/发布系统,写的很简洁,但是非常的完美。
/* jQuery Tiny Pub/Sub - v0.7 - 10/27/2011
* http://benalman.com/
* Copyright (c) 2011 "Cowboy" Ben Alman; Licensed MIT, GPL */
(function($) {
var o = $({});
$.subscribe = function() {
o.on.apply(o, arguments);
};
$.unsubscribe = function() {
o.off.apply(o, arguments);
};
$.publish = function() {
o.trigger.apply(o, arguments);
};
}(jQuery));
/* jQuery Tiny Pub/Sub - v0.7 - 10/27/2011
* http://benalman.com/
* Copyright (c) 2011 "Cowboy" Ben Alman; Licensed MIT, GPL */
(function(a){var b=a({});a.subscribe=function(){b.on.apply(b,arguments)},a.unsubscribe=function(){b.off.apply(b,arguments)},a.publish=function(){b.trigger.apply(b,arguments)}})(jQuery)
@creamidea
Copy link
Author

只是一个订阅/发布系统,这段程序构建在jQuery上,写的很简洁,很完美啊。

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