SOURCE

var Event = (function () {
    var clientList = {}
    var listen = {}
    var trigger = {}
    var remove = {}

    // 监听
    listen = function (key, fn) {
        if (!clientList[key]) {
            clientList[key] = [];
        }
        clientList[key].push(fn);
    }

    // 触发监听
    trigger = function () {
        let key = Array.prototype.shift.call(arguments)
        let fns = clientList[key]
        if (!fns || fns.length === 0) return false
        for (let i = 0; i < fns.length; i++) {
            fns[i].apply(this, arguments)
        }
    }

    // 删除监听
    remove = function (key, fn) {
        var fns = clientList[key];
        if (!fns) return false
        if (!fn) { // 全部删除
            fns && (fns.length = 0)
        }
        else {
            for (let i = this.clientList.length - 1; i >= 0; i--) {
                if (fn === this.clientList[i]) {
                    this.clientList.splice(i, 1)
                }
            }
        }
    }

    return {
        listen: listen,
        trigger: trigger,
        remove: remove
    }
})()

Event.listen('88', function (price) {
    console.log('价格= ' + price);
})
Event.trigger('88', 20000)
console 命令行工具 X clear

                    
>
console