//全局通知 var Notification = { _eventMap: [], on: function (masgId, callback, target) { if (this._eventMap[masgId] === undefined) { this._eventMap[masgId] = []; } this._eventMap[masgId].push({ callback: callback, target: target }); }, emit: function (masgId, parameter) { let array = this._eventMap[masgId]; if (array === undefined) return; for (let i = 0; i < array.length; i++) { let element = array[i]; if (element) element.callback.call(element.target, parameter); } }, off: function (masgId, callback) { let array = this._eventMap[masgId]; if (array === undefined) return; for (let i = 0; i < array.length; i++) { let element = array[i]; if (element && element.callback === callback) { array[i] = undefined; break; } } }, offMasgId: function (masgId) { this._eventMap[masgId] = undefined; }, removeAllMsg: function () { for (let k in this._eventMap) { if (this._eventMap[k]) { this.offMasgId(k); } } } }; export { Notification };