define(function (require, exports, module) {
    'use strict';

    var Msg = function () {
        return {
            stack : {},  // 事件

            on : function (eventName, callback) {
                if (!eventName || !_.isFunction(callback)) {
                    throw new Error('事件注册参数错误！');
                }

                this.stack[eventName] = this.stack[eventName] || [];
                this.stack[eventName].push(callback);
            },

            fire : function (eventName, params) {
                if (!_.isString(eventName)) {
                    throw new Error('事件触发参数错误！');
                }
                var args = [].slice.call(arguments, 1); // 获取参数
                var events = this.stack[eventName];
                _.each(events, function (callback) {
                    callback.apply(null, args);
                });
            }

        }
    }

    module.exports = new Msg();

});