<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Document</title>
</head>
<body>
<script>
function A(){
this.name = 'yao';
this.age = '30';
this.say = function () {
return this.name;
}
// console.log(arguments);
}
//A();
// var obj = {
// a: 1,
// b:2,
// c: new Date()
// }
var obj = new A(11);
function deepClone(obj) {
if(obj == null) return null;
if(typeof obj !== 'object') return obj;
if(obj instanceof RegExp) {
return new RegExp(obj);
}
if(obj instanceof Date) {
return new Date(obj);
}
let newObj = new obj.constructor;
for(let key in obj) {
if(obj.hasOwnProperty(key)) {
newObj[key] = deepClone(obj[key]);
}
}
return newObj;
}
let obj2 = deepClone(obj);
console.log(obj, obj2);
console.log(obj.constructor, obj2.constructor);
console.log(obj == obj2);
</script>
</body>
</html>