淺克隆的實現(xiàn):
function extendCopy(obj) {
var newObj = {}
for(var i in obj){
newObj[i] = obj[i]
}
return newObj
}
深度克隆的實現(xiàn):
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
}