Object.assign 能夠把 n 個源對象拷貝到目標對象中去,以下app
let m ={name: {asd: '123'}}spa
let n = Object.assign({}, m)對象
console.log(n)console
運行結果apple
{name: {asd: '123'}}co
那究竟是深拷貝仍是淺拷貝呢,答案是第一級屬性深拷貝,之後級別屬性淺拷貝 。你們看下面兩段代碼let
let s ={name: {asd: '123'}}
let d = Object.assign({}, s)
d.name.asd = '123456789'
console.log(d, s)