当前位置:网站首页>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() .边栏推荐
- Jianzhi offer 04 (implemented in C language)
- Digital simulation beauty match preparation -matlab basic operation No. 6
- Appscan installation steps
- unit testing
- Unittest+airtest+beatiulreport combine the three to make a beautiful test report
- [Galaxy Kirin V10] [server] system startup failed
- [Galaxy Kirin V10] [desktop] printer
- Canoe - the third simulation project - bus simulation-1 overview
- Canoe: the fourth simulation project -- bug debugging experience
- Locust installation
猜你喜欢

Canoe - description of common database attributes

XMIND installation

Using Lua to realize 99 multiplication table

Elevator dispatching (pairing project) ②
![[Galaxy Kirin V10] [server] FTP introduction and common scenario construction](/img/ef/f0f722aaabdc2d98723cad63d520e0.jpg)
[Galaxy Kirin V10] [server] FTP introduction and common scenario construction
![[machine] [server] Taishan 200](/img/e5/69a1a4ca04814a033a77d3cb4601b3.jpg)
[machine] [server] Taishan 200

Oracle11g | getting started with database. It's enough to read this 10000 word analysis

Elevator dispatching (pairing project) ③

TS type gymnastics: illustrating a complex advanced type
![[Galaxy Kirin V10] [desktop] cannot add printer](/img/a6/28e4aa31e805a018e6db2b32ca1be0.jpg)
[Galaxy Kirin V10] [desktop] cannot add printer
随机推荐
Snake (C language)
TS type gymnastics: illustrating a complex advanced type
Deepmind proposed a Zuan AI, which specially outputs network attack language
Communication layer of csframework
1. Circular nesting and understanding of lists
Heartbeat启动后无反应
Write a program to judge whether the two arrays are equal, and then write a similar program to compare the two vectors.
[Galaxy Kirin V10] [server] soft RAID configuration
Huge number multiplication (C language)
[advantages and disadvantages of outsourcing software development in 2022]
I What is security testing
How to use diff and patch to update the source code
LVS+Keepalived实现四层负载及高可用
Recursive method to achieve full permutation (C language)
Notes on writing test points in mind mapping
Terms related to hacker technology
Error C4996 ‘WSAAsyncSelect‘: Use WSAEventSelect() instead or define _ WINSOCK_ DEPRECATED_ NO_ WARN
VPS安装Virtualmin面板
Sword finger offer 05 (implemented in C language)
Strings and characters