assign复制对象_对象的assign()⽅法
assign复制对象
清空回收站快捷键Introduced in ES2015, this method copies all the enumerable own properties of one or more objects into another.
如何取消流量套餐此⽅法在ES2015中ES2015 ,将⼀个或多个对象的所有可枚举的⾃⾝属性复制到另⼀个对象中。
Its primary u ca is to create a shallow copy of an object.
商品购销合同范本它的主要⽤例是创建对象的浅表副本。
const copied = Object.assign({}, original)
Being a shallow copy, values are cloned, and objects references are copied (not the objects themlves), so if you edit an object property in the original object, that’s modified also in the copied object, since the referenced inner object is the same:
小花折纸作为浅表副本,将克隆值并复制对象引⽤(⽽不是对象本⾝),因此,如果在原始对象中编辑对象属性,则在复制的对象中也将对其进⾏修改,因为引⽤的内部对象是相同的:
const original = {
name: 'Fiesta',
car: {
color: 'blue'
}
}
const copied = Object.assign({}, original)
original.name = 'Focus'
lor = 'yellow'
copied.name //Fiesta
lor //yellow
小洲村
I mentioned “one or more”:
我提到“⼀个或多个”:
const wiPerson = {
isWi: true
}
const foolishPerson = {
isFoolish: true
}狗为什么不能吃巧克力
const wiAndFoolishPerson = Object.assign({}, wiPerson, foolishPerson)
console.log(wiAndFoolishPerson) //{ isWi: true, isFoolish: true }
送妈妈的礼物
象拔蚌多少钱一斤assign复制对象