判断类型及深拷贝

function judgeTypeFnCreator (type) {
const toString = Object.prototype.toString
return function isType (o) {
return toString.call(o) === `[object ${type}]`
}
}
 
 
const isFunc = judgeTypeFnCreator('Function')
const isUndef = judgeTypeFnCreator('Undefined')
const isArray = judgeTypeFnCreator('Array')
const isString = judgeTypeFnCreator('String')
const isObject = judgeTypeFnCreator('Object')
const isNumber = judgeTypeFnCreator('Number')
 
 
function deepAssign(to, from) {
for (let key in from) {
if (!to[key] || typeof to[key] !== 'object') {
to[key] = from[key]
} else {
deepAssign(to[key], from[key])
}
}
}
原文地址:https://www.cnblogs.com/liuhao-web/p/10756144.html