assign复制对象_对象的assign()⽅法
bibfassign复制对象
国贸专业就业方向
美国之声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: {teabag
color: 'blue'美国恐怖故事 第三季
}
}
const copied = Object.assign({}, original)
original.name = 'Focus'
lor = 'yellow'
copied.name //Fiesta
lor //yellow
I mentioned “one or more”:butcher是什么意思
我提到“⼀个或多个”:
const wiPerson = {
isWi: true
}learn chine
const foolishPerson = {
isFoolish: true
entitle}五年级上册英语第一单元
const wiAndFoolishPerson = Object.assign({}, wiPerson, foolishPerson)
console.log(wiAndFoolishPerson) //{ isWi: true, isFoolish: true }
life is a struggleassign复制对象