方法一:
function clone(param){
if(typeof param != Object){
return param;
}
else if(param instanceof Array){
var array = [];
for(var i = 0; i < param.length; i++){
array[i] = param[i];
}
return array;
}
else if(param instanceof Object){
var p;
var cloneObj={};
for(p in param){
cloneObj[p] = param[p];
}
return cloneObj;
}
}
方法二:
var obj1 = {a:1};
var obj2 = JSON.parse(JSON.stringify(obj1));