let obj = {
? ? ? name:'zhagnsan',
? ? ? age:30,
? ? ? school:'pinghai'
? ? }
? object.assign
? ? function copy(obj){
? ? ? return Object.assign({},obj)
? ? }
? ? console.log(copy(obj))
? ??...展開(kāi)運(yùn)算符
? ? function copy2(obj){
? ? ? return {...obj}
? ? }
? ? console.log(copy2(obj))
? ? let a = {
? ? ? age:1,
? ? ? jobs:{first:'FE'}
? ? }
? ? let b = copy(a)
? ? a.jobs.first = 'native'
? ? console.log(b.jobs.first)
? ? console.log(a.jobs.first)
? ? //淺拷貝,當(dāng)對(duì)象層級(jí)大于2級(jí)時(shí)候,原來(lái)的對(duì)象屬性也被改變了
? ?深拷貝
? ? function copyDeep(obj){
? ? ? return JSON.parse(JSON.stringify(obj))
? ? }
? ? console.log(copyDeep(obj))
? ?messageChannel
? ? function structuralClone(){
? ? ? return new Promise(resolve =>{
? ? ? ? const{port1,port2} = new MessageChannel()
? ? ? ? port2.onmessage = ev => resolve(ev.data)
? ? ? ? port1.postMessage(obj)
? ? ? })
? ? }
? ? obj2 = structuralClone(obj)
? ? console.log(obj2)