浅克隆的实现:
function extendCopy(obj) {
var newObj = {}
for(var i in obj){
newObj[i] = obj[i]
}
return newObj
}
深度克隆的实现:
function extendDeepCopy(obj, newObj){
var newObj = newObj || {}
for(var i in obj){
if(typeof obj[i] == "object"){
newObj[i] = (obj[i].constructor === Array) ? [] : {}
extendDeepCopy(obj[i], newObj[i])
}else{
newObj[i] = obj[i]
}
}
return newObj
}