SOURCE

// 判断数据类型
// function myTypeof(obj){
//     return Object.prototype.toString.call(obj).slice(8,-1).toLowerCase()
// }
// console.log(myTypeof([]))
// console.log(myTypeof(''))
// console.log(myTypeof(1))

// ES5数组去重
// function unique(arr){
//     return arr.filter((item,index,arr)=>{
//         return arr.indexOf(item)===index
//     })
// }
// console.log(unique([1,3,2,3,4,5,63,2,'1','1',null,null,undefined,undefined,{},{}]))
// console.log([...new Set([1,3,2,3,4,5,63,2,'1','1',null,null,undefined,undefined,{},{}])])

// // 数组扁平化
// function flatten(arr){
//     while(arr.some(item=>Array.isArray(item))){
//         arr = [].concat(...arr)
//     }
//     return arr
// }

// class EventEmitter{
//     constructor(){
//         this.cache = {}
//     }
//     on(name,fn){
//         if(this.cache[name]){
//             this.cache[name].push(fn)
//         }else{
//             this.cache[name] = [fn]
//         }
//     }

//     off(name,fn){
//         let tasks = this.cache[name];
//         if(tasks){
//             const index = tasks.findIndex(f=>f===fn||f.callback===fn)
//             if(index>=0){
//                 tasks.splice(index,1)
//             }
//         }
//     }
//     emit(name,once=false,...args){
//         if(this.cache[name]){
//             // 创建副本,如果回调函数内继续注册相同事件,会造成死循环
//             let tasks = this.cache[name].slice();
//             for(let fn of tasks){
//                 fn(...args)
//             }
//             if(once){
//                 delete this.cache[name]
//             }
//         }
//     }
// }

// let eventBus = new EventEmitter();
// let fn1 = function(name,age){
//     console.log(`${name}  ${age}`)
// }
// let fn2 = function(name, age) {
// 	console.log(`hello, ${name} ${age}`)
// }
// eventBus.on('aaa',fn1);
// eventBus.on('aaa',fn2);
// eventBus.emit('aaa',false,'不懒',12)

function debouce(fn,wait){
    let timeout = null;
    return function(){
        let context = this;
        let args = arguments;
        clearTimeout(timeout)
        timeout = setTimeout(()=>{
            fn.apply(context,args)
        },wait)
    }
console 命令行工具 X clear

                    
>
console