当前位置:网站首页>Object. Assign () & JS (= >) arrow function & foreach () function
Object. Assign () & JS (= >) arrow function & foreach () function
2022-07-04 10:58:00 【ths512】
Object.assign() Method to copy the values of all enumerable properties from one or more source objects to the target object . It will return the target object .
Object.assign(target, ...sources) 【target: Target audience 】,【souce: Source object ( Can be more )】
Take a chestnut :
const object1 = {
a: 1,
b: 2,
c: 3
};
const object2 = Object.assign({c: 4, d: 5}, object1);
console.log(object2.c, object2.d);
console.log(object1) // { a: 1, b: 2, c: 3 }
console.log(object2) // { c: 3, d: 5, a: 1, b: 2 }
Be careful :
1. If the properties in the target object have the same key , Then the attribute will be overridden by the attribute in the source object . The properties of the subsequent source object will similarly override the properties of the previous source object
2.Object.assign Method copies only the properties of the source object itself and can be enumerated to the target object . This method uses the [[Get]] And the target
Object's [[Set]], So it calls correlation getter and setter. therefore , It assigns properties , Instead of just copying or defining new properties . Such as
The merge source contains getter, This may make it unsuitable to incorporate new attributes into the prototype . To define properties ( Including its enumerability ) Copied to the
Prototype , You should use Object.getOwnPropertyDescriptor() and Object.defineProperty() .边栏推荐
- Notes on writing test points in mind mapping
- Heartbeat报错 attempted replay attack
- Locust learning record I
- [Galaxy Kirin V10] [desktop] build NFS to realize disk sharing
- [advantages and disadvantages of outsourcing software development in 2022]
- Jemeter script recording
- [test theory] test process management
- JMeter common configuration components and parameterization
- PHP programming language (1) - operators
- JMeter Foundation
猜你喜欢

Collection of practical string functions

How do microservices aggregate API documents? This wave of show~

Replace() function

20 minutes to learn what XML is_ XML learning notes_ What is an XML file_ Basic grammatical rules_ How to parse

Huge number (C language)
![[Galaxy Kirin V10] [server] NUMA Technology](/img/9b/65466c6fc6336e27e842f50c26b9c3.jpg)
[Galaxy Kirin V10] [server] NUMA Technology
![[Galaxy Kirin V10] [desktop] FTP common scene setup](/img/f6/e4fbfe69a6a7635ee6364114c46fd8.jpg)
[Galaxy Kirin V10] [desktop] FTP common scene setup

Elevator dispatching (pairing project) ④
![[test theory] test process management](/img/d2/65865dffacf38d9a8be720868b75f0.jpg)
[test theory] test process management

F12 clear the cookies of the corresponding web address
随机推荐
1. Circular nesting and understanding of lists
20 minutes to learn what XML is_ XML learning notes_ What is an XML file_ Basic grammatical rules_ How to parse
The last month before a game goes online
Canoe - the third simulation project - bus simulation - 3-1 project implementation
[advantages and disadvantages of outsourcing software development in 2022]
Get the data of the top 100 headlines today with Tianxing data
[Galaxy Kirin V10] [server] grub default password
Jemeter plug-in technology
Interview and lecture summary 1
Huge number multiplication (C language)
Locust installation
Notes on writing test points in mind mapping
The bamboo shadow sweeps the steps, the dust does not move, and the moon passes through the marsh without trace -- in-depth understanding of the pointer
iptables导致Heartbeat脑裂
regular expression
Add t more space to your computer (no need to add hard disk)
XMIND installation
51 data analysis post
Advanced order of function
Function introduction of canbedded component