Last active
December 18, 2015 07:58
-
-
Save monjer/787f98373b7a5bc4d85e to your computer and use it in GitHub Desktop.
使用jQuery的自定义事件机制实现消息中心
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| (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
commented
Nov 3, 2015
Author
- Pub Sub Pattern using jQuery .on() and .off()
- jQuery Custom Events
- Publish/Subscribe with jQuery Custom Events
- jQuery Tiny Pub/Sub
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment