How to do it...

  1. Open your command-line application, and navigate to your workspace.
  2. Create a new folder named 10-08-combine-arrays-using-spread.
  3. Create a main.js file that defines a new class named Rocket that takes a constructor argument name and assigns it to an instance property:
// main.js 
class Rocket { 
  constructor(name) { 
    this.name = name; 
  } 
   } 
  1. Create a main function with multiple array rockets, divided by nationality, and a standalone Rocket variable:
// main.js 
export function main() { 
  const usRockets= [ 
    new Rocket('US: Saturn V'), 
    new Rocket('US: Falcon Heavy') 
  ]; 
 
  const sovietRocket = new Rocket('USSR: Soyuz'); 
 
  const chineseRockets = [ 
    new Rocket('CN: Dong Feng'), 
    new Rocket('CN: Long March') 
  ]; 
}  
  1. Use the structuring syntax ...

Get ECMAScript Cookbook now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.