一个新的对象直接拷贝已存在的对象的对象属性的引用,即浅拷贝。 Array.prototype.slice()属于浅拷贝。

var arr = [2, 4, 6, { y: 10 }]
var newArr = arr.slice()
newArr[3].x = 20
newArr[3].y = 30
console.log(arr)     // [2, 5, 6, { y: 30, x: 20 }]
console.log(newArr)  // [2, 5, 6, { y: 30, x: 20 }]

浅拷贝只拷贝已存在对象的对象属性的引用,其余非对象属性是占用新的内存空间,并非与原对象共享。 var newArr = Array.prototype.slice.call(arr) newArr[1] = 50 console.log(arr) // [2, 4, 6, { y: 10 }] console.log(newArr) // [2, 50, 6, { y: 10 }]