February 2019
Beginner
694 pages
18h 4m
English
When working with basic JavaScript objects, we often need to copy the properties of one object to another, or do some mixing and matching of properties from various objects. Similar to the way that we defined a function as having a variable number of arguments, we can use this same syntax on standard objects. This technique is called object rest and spread. Consider the following TypeScript code:
let firstObj = { id: 1, name: "firstObj" };
let secondObj = { ...firstObj };
console.log(`secondObj : ${JSON.stringify(secondObj)}`);
Here, we start by defining a simple JavaScript object named firstObj, that has an id and a name property. We then use the new ES7 syntax to copy all of the properties of firstObj into another ...
Read now
Unlock full access