function subscribe(callback) {

        // 添加回调
        if (typeof callback === 'function') {
            listeners.push(callback);
        }

        // 返回取消函数
        return function unsubscribe() {
            listeners = listeners.filter(v => v !== callback);
        };
    }
function subscribe(callback) {

        
        if (typeof callback === 'function') {
            listeners.push(callback);
        }

        
        return function unsubscribe() {
            listeners = listeners.filter(v => v !== callback);
        };
    }
function subscribe ( callback ) { // 添加回调 if ( typeof callback === 'function' ) { listeners . push ( callback ) ; } // 返回取消函数 return function unsubscribe ( ) { listeners = listeners . filter ( v => v !== callback ) ; } ; }
添加监听
添加监听