实现js中所有对象的深度克隆(包装对象,Date对象,正则对象)
var clone = function (obj) {
___if(obj === null) return null
___if(typeof obj !== 'object') return obj;
___if(obj.constructor===Date) return new Date(obj);
___if(obj.constructor === RegExp) return new RegExp(obj);
___var newObj = new obj.constructor (); //保持继承链
___for (var key in obj) {
______if (obj.hasOwnProperty(key)) { //不遍历其原型链上的属性
_________var val = obj[key];
_________newObj[key] = typeof val === 'object' ? arguments.callee(val) : val; // 使用arguments.callee解除与函数名的耦合
______}
___}
___return newObj;
};