判断类型及深拷贝

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])
}
}
}
posted @ 2019-04-23 14:20  刘浩2561179983  阅读(271)  评论(0编辑  收藏  举报