当前位置:网站首页>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() .边栏推荐
- [test theory] test phase analysis (unit, integration, system test)
- software test
- Locust installation
- JMeter assembly point technology and logic controller
- I What is security testing
- Appscan installation steps
- Write a program to judge whether the elements contained in a vector < int> container are 9.20: exactly the same as those in a list < int> container.
- Aike AI frontier promotion (2.14)
- Introduction to Lichuang EDA
- How to use diff and patch to update the source code
猜你喜欢

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

Sword finger offer 05 (implemented in C language)

Add t more space to your computer (no need to add hard disk)

Failed to configure a DataSource: ‘url‘ attribute is not specified... Bug solution

Collection of practical string functions
![[Galaxy Kirin V10] [server] NFS setup](/img/ed/bd7f1a1e4924a615cb143a680a2ac7.jpg)
[Galaxy Kirin V10] [server] NFS setup

Performance test method

Error C4996 ‘WSAAsyncSelect‘: Use WSAEventSelect() instead or define _ WINSOCK_ DEPRECATED_ NO_ WARN

JMeter common configuration components and parameterization

Function introduction of canbedded component
随机推荐
[Galaxy Kirin V10] [server] NUMA Technology
Introduction to Lichuang EDA
Canoe-the second simulation project-xvehicle-1 bus database design (idea)
Write a thread pool by hand, and take you to learn the implementation principle of ThreadPoolExecutor thread pool
Failed to configure a DataSource: ‘url‘ attribute is not specified... Bug solution
Write a program to judge whether the elements contained in a vector < int> container are 9.20: exactly the same as those in a list < int> container.
Advanced order of function
Appscan installation error: unable to install from Net runtime security policy logout appscan solution
Function introduction of canbedded component
Canoe: the fourth simulation project -- bug debugging experience
Canoe: distinguish VT, VN and vteststudio from their development history
iptables导致Heartbeat脑裂
Oracle11g | getting started with database. It's enough to read this 10000 word analysis
试题库管理系统–数据库设计[通俗易懂]
VPS安装Virtualmin面板
Swagger and OpenAPI
Dichotomy search (C language)
[Galaxy Kirin V10] [server] set time synchronization of intranet server
Snake (C language)
Terms related to hacker technology