implement Object.assign()
2022年5月1日小于 1 分钟
implement Object.assign()
Question
The Object.assign()
method copies all enumerable own properties from one or more source objects to a target object. It returns the target object. (source: MDN)
It is widely used, Object Spread operator actually is internally the same as Object.assign()
(source). Following 2 lines of code are totally the same.
let aClone = { ...a };
let aClone = Object.assign({}, a);
This is an easy one, could you implement Object.assign()
with your own implementation ?
note
Don't use Object.assign() in your code It doesn't help improve your skills
Code
/**
* @param {any} target
* @param {any[]} sources
* @return {object}
*/
function objectAssign(target, ...sources) {
// your code here
}