@c-Ku
2017-11-03T07:32:14.000000Z
字数 533
阅读 594
JavaScript
代码示例
// Based on ES5var login = {};login.eventList = {};// 将函数推入数组中保存,待用login.listen = function(key, fn) {if (!this.eventList[key]) {this.eventList[key] = [];}this.eventList[key].push(fn);}login.trigger = function(key) {var fns = this.eventList[key];if (!fns || fns.length === 0) {return false;}for (var i=0; i<fns.length;i++) {fns[i]();}}// 订阅login.listen('loginSuccess', function() {console.log('显示用户头像');})login.listen('loginSuccess', function() {console.log('显示消息列表');})// 发布login.trigger('loginSuccess');
