当前位置:网站首页>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() .
边栏推荐
- Elevator dispatching (pairing project) ④
- Capl: timer event
- Summary of several job scheduling problems
- Virtual machine configuration network
- Canoe: the fourth simulation project -- bug debugging experience
- Strings and characters
- Time complexity and space complexity
- Collection of practical string functions
- Read a piece of text into the vector object, and each word is stored as an element in the vector. Convert each word in the vector object to uppercase letters. Output the converted elements in the vect
- [Galaxy Kirin V10] [desktop] can't be started or the screen is black
猜你喜欢
Canoe - the third simulation project - bus simulation - 3-2 project implementation
Canoe - the third simulation project - bus simulation-1 overview
Add t more space to your computer (no need to add hard disk)
Oracle11g | getting started with database. It's enough to read this 10000 word analysis
Quick sort (C language)
Canoe - description of common database attributes
Learning XML DOM -- a typical model for parsing XML documents
Elevator dispatching (pairing project) ②
Canoe - the third simulation project - bus simulation - 3-1 project implementation
[Galaxy Kirin V10] [desktop] printer
随机推荐
Capl: timer event
Knapsack problem and 0-1 knapsack problem
How do microservices aggregate API documents? This wave of show~
/*Rewrite the program, find the value of the element, and return the iterator 9.13: pointing to the found element. Make sure that the program works correctly when the element you are looking for does
Safety testing aspects
Elevator dispatching (pairing project) ①
[test theory] test process management
[Galaxy Kirin V10] [server] set time synchronization of intranet server
SSH原理和公钥认证
PHP programming language (1) - operators
Huge number multiplication (C language)
regular expression
Oracle11g | getting started with database. It's enough to read this 10000 word analysis
Open the neural network "black box"! Unveil the mystery of machine learning system with natural language
[Galaxy Kirin V10] [server] soft RAID configuration
Elevator dispatching (pairing project) ③
[Galaxy Kirin V10] [server] system partition expansion
Canoe: distinguish VT, VN and vteststudio from their development history
Canoe - the second simulation engineering - xvehicle - 2 panel design (operation)
Communication layer of csframework