我对javascript对象(数组)深度复制有问题.我读了很多很好的应对方法.我还知道jQuery有美元.将API扩展到这个问题.但我的问题是:我能用JSON字符串化和解析方法来解决这个问题吗?
以下是我的代码:
function deepCopy(oldValue) {
var newValue
strValue = JSON.stringify(oldValue)
return newValue = JSON.parse(strValue)
}
var a = {
b: 'b',
c: [1,2,4],
d: null
}
copy = deepCopy(a)
console.log(a === copy) // false
console.log(a.c === copy.c) // false
PS:我知道,如果没有,所有对象都是可序列化的,但我知道的唯一情况是,当对象包含一个属性,即函数时.还有其他情况吗?