-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathobject-assign.js
More file actions
35 lines (28 loc) · 1018 Bytes
/
object-assign.js
File metadata and controls
35 lines (28 loc) · 1018 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
//! The Object.assign() method copies all enumerable own properties from one or more source objects to a target object. It returns the target object.
//?Object.assign() does not create and return a new object; it directly modifies then returns the same target object that was passed in
const target = { a: 1, b: 2 };
const source = { b: "Rakib", c: "Rakin" };
const target2 = Object.assign(target, source);
console.log(target);
console.log(target2);
const newTarget = {};
const newSource = { num: 49 };
Object.assign(newTarget, newSource);
console.log(newTarget);
const duck = {
hasBill: true,
};
const beaver = {
hasTail: true,
};
const otter = {
hasFur: true,
feet: "webbed",
};
const platypus = Object.assign({}, duck, beaver, otter);
console.log(platypus);
//! platypus doesn't exist in any of the three source objects' prototype chains
console.log(platypus.constructor);
console.log(platypus.isPrototypeOf(duck));
console.log(duck.isPrototypeOf(platypus));
console.log(beaver.isPrototypeOf(duck));