当前位置:网站首页>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() .
边栏推荐
- Strings and characters
- [advantages and disadvantages of outsourcing software development in 2022]
- Fundamentals of software testing
- LVS+Keepalived实现四层负载及高可用
- DDL language of MySQL database: create, modify alter, delete drop of databases and tables
- On binary tree (C language)
- Design and common methods of test case documents
- [test theory] test phase analysis (unit, integration, system test)
- Day7 list and dictionary jobs
- Canoe: the difference between environment variables and system variables
猜你喜欢
Huge number (C language)
Error C4996 ‘WSAAsyncSelect‘: Use WSAEventSelect() instead or define _ WINSOCK_ DEPRECATED_ NO_ WARN
F12 clear the cookies of the corresponding web address
Canoe test: two ways to create CAPL test module
Elevator dispatching (pairing project) ③
Collection of practical string functions
Hidden C2 tunnel -- use of icmpsh of ICMP
[Galaxy Kirin V10] [server] NFS setup
VI text editor and user rights management, group management and time management
Personal thoughts on the development of game automation protocol testing tool
随机推荐
Heartbeat报错 attempted replay attack
Analysis function in SQL
[Galaxy Kirin V10] [server] iSCSI deployment
JMeter common configuration components and parameterization
Virtual machine configuration network
[advantages and disadvantages of outsourcing software development in 2022]
Canoe: distinguish VT, VN and vteststudio from their development history
[Galaxy Kirin V10] [server] NUMA Technology
How to deal with the relationship between colleagues
[Galaxy Kirin V10] [desktop] FTP common scene setup
Locust learning record I
How to use diff and patch to update the source code
/*The rewriter outputs the contents of the IA array. It is required that the type defined by typedef cannot be used in the outer loop*/
[Galaxy Kirin V10] [desktop and server] FRP intranet penetration
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
2022 ape circle recruitment project (software development)
Write a program to define an array with 10 int elements, and take its position in the array as the initial value of each element.
Replace() function
Quick sort (C language)
Remove linked list elements