SOURCE

//事件循环  
// console.log(1)
// setTimeout(() => { 
//     console.log('2') 
//     Promise.resolve(4).then((res) => console.log(res))
// }, 0);
// setTimeout(() => { 
//     console.log('3')
// }, 0);

// //手写防抖
// function deb(){
//     let timer = null;
//     return function(...args){
//         if(timer) clearTimeout(timer)
//         timer = setTimeout(()=>{
//             fn.applay(this,fn)
//             timer = null
//         })
//     }
// }
// //手写节流
// function thr(fn,delay){
//     let timer = null;
//     return function(...args){
//         if(timer) return
//         timer = setTimeout(()=>{
//             fn.applay(this,args)
//             time = null;
//         },delay)
//     }
// }

//手写闭包
// var add = (function(){
//     let count =  0;
//     return function(){ return count += 1}
// })()
// add()
// console.log(add())

// 手写Apply
// var v = 1;
// Function.prototype.myApply = function(_this,args=[]){
//     if(!_this){
//         _this = Object.create(null)
//     }
//     _this.fn = this
//     const res = _this.fn(...args)
//     delete _this.fn
//     return res;
// }

// function sum(a,b){
//     return this.v + a + b
// }

// console.log('sum:'+sum.myApply(this,[2,3]))

//手写call
// Function.prototype.myCall = function(_this, ...args){
//     if(!_this) _this = Object.create(null) // 如果this不是对象?
//     _this.fn = this
//     const res = _this.fn(...args)
//     delete _this.fn
//     return res
// }

// function sum(a,b){
//     return this.v + a + b
// }

// console.log('sum:'+sum.myCall({v:1},2,3))

//手写Bind *******暂时还不会
// Function.prototype.myBind = function(_this, ...args) {
// 	const fn = this
// 	return function F(...args2) {
// 		return this instanceof F ? new fn(...args, ...args2):fn.apply(_this, args.concat(args2))
// 	}
// }
// //使用
// function Sum (a, b) {
// 	this.v= (this.v || 0)+ a + b
// 	return this
// }
// // const NewSum = Sum.myBind({v: 1}, 2)
// const NewSum = Sum.myBind({v: 1}, 2)
// console.log(NewSum(3)) // 调用:{v: 6}
// console.log(new NewSum(3)) // 构造函数:{v: 5} 忽略 myBind 绑定this

// function deepClone(obj) {
//     if (typeof obj != Object) return obj; //如果obj不是对象则直接返回
//     var temp = Array.isArray(obj) ? [] : {}; //判断对象是不是数组,用来生命返回的数据结构
//     for (let key in obj) {  //遍历每一个
//         // console.log(key)
//         if (obj.hasOwnProperty(key)) {
//             if (obj[key] && typeof obj[key] == 'object') { // 如果obj[key]还是对象则执行递归
//                 // console.log(obj[key])
//                 temp[key] = deepClone(obj[key]); // 递归
//             } else {
//                 temp[key] = obj[key];
//                 // console.log(temp[key])
//             }
//         }
//     }
//     return temp;
// }

// var obj = {
//     age: 13,
//     name: {
//         addr: '天边'
//     }
// }
// // var obj = [1,2,3,[40,5,6,[70,8,90]]]
// var obj2 = deepClone(obj);
// console.log(obj2 === obj); //13
// obj2.age = 14
// obj2.name.addr = '地心'
// console.log(obj.age); //13
// console.log(obj.name.addr); //天边
// console.log(obj2.age); //13
// console.log(obj2.name.addr); //天边
// console.log(obj2); //天边

console 命令行工具 X clear

                    
>
console