EventCenter.js 662 B

12345678910111213141516171819202122232425
  1. var EventCenter = {
  2. addEventHandler: function (eventName, callback) {
  3. if(!this.handles){
  4. this.handles={};
  5. }
  6. if(!this.handles[eventName]){
  7. this.handles[eventName]=[];
  8. }
  9. this.handles[eventName].push(callback);
  10. },
  11. emit: function (eventName) {
  12. if(this.handles[arguments[0]]){
  13. for(var i=0;i<this.handles[arguments[0]].length;i++){
  14. this.handles[arguments[0]][i](arguments[1]);
  15. }
  16. }
  17. },
  18. removeEventHandler: function (eventName) {
  19. if(this.handles[eventName]){
  20. delete this.handles[eventName];
  21. }
  22. }
  23. };