手写一个JS深拷贝
乞丐版:
var newObj = JSON.parse( JSON.stringify( someObj ) );
面试够用版:
function deepCopy(obj){
//判断是否是简单数据类型,
if(typeof obj == "object"){
//复杂数据类型
var result = obj.constructor == Array ? [] : {};
for(let i in obj){
result[i] = typeof obj[i] == "object" ? deepCopy(obj[i]) : obj[i];
}
}else {
//简单数据类型 直接 == 赋值
var result = obj;
}
return result;
}
手写一个Promise
(中高级必考)
具体请戳下面链接
https://juejin.im/post/5c9c3989e51d454e3a3902b6#heading-12