1var x = {myProp: "value"};
2var xClone = Object.assign({}, x);
3
4//Obs: nested objects are still copied as reference.
1const target = { a: 1, b: 2 };
2const source = { b: 4, c: 5 };
3
4const returnedTarget = Object.assign(target, source);
5
6console.log(target);
7// expected output: Object { a: 1, b: 4, c: 5 }
8
9console.log(returnedTarget);
10// expected output: Object { a: 1, b: 4, c: 5 }
11
1The Object.assign() method copies all enumerable own properties from one or more source objects to a target object. It returns the target object.
2const target = { a: 1, b: 2 };
3const source = { b: 4, c: 5 };
4
5const returnedTarget = Object.assign(target, source);
6
7console.log(target);
8// expected output: Object { a: 1, b: 4, c: 5 }
9
10console.log(returnedTarget);
11// expected output: Object { a: 1, b: 4, c: 5 }
1let voleur = {
2 action : () =>console.log ('Coup de dague fatal') ,
3 crie : ('pour la horde!!!!') ,
4 coupfatal :()=> console.log ('coup dans le dos')
5
6}
7
8voleur.action() ;
9voleur.coupfatal() ;
10console.log(voleur.crie) ;
11