Javascript简单实现对象深拷贝
利用递归方式遍历所有属性进行深层对象拷贝,支持拷贝函数,对象,数组等:
function cloneDeep(object) { if (typeof (object) == 'object') { if (Array.isArray(object)) { var obj = [] } else { var obj = {} } for (key in object) { if (typeof (object[key]) == 'object') { obj[key] = cloneDeep(object[key]) } else { obj[key] = object[key] } } } else { var obj = object } return obj }