카테고리 없음

Named Imports

더 멋진 세상을 꿈꾸는 개발자 2020. 5. 14. 18:37

Named Imports

To import objects stored in a variable, we use the import keyword and include the variables in a set of {}.

In the order.js file, for example, we would write:

 

import { specialty, isVegetarian } from './menu';

console.log(specialty);

 

 

  1. Here specialty and isVegetarian are imported.
  2. If we did not want to import either of these variables, we could omit them from the import statement.
  3. We can then use these objects as in within our code. For example, we would use specialty instead of Menu.specialty.

import {availableAirplanes, flightRequirements, meetsStaffRequirements} from './airplane';

function displayFuelCapacity() {
  availableAirplanes.forEach(function(element){
  console.log('Fuel Capacity of ' + element.name + ': ' + element.fuelCapacity);
  });
}

displayFuelCapacity();

function displayStaffStatus() {
  availableAirplanes.forEach(function(element) {
   console.log(element.name + ' meets staff requirements: ' + meetsStaffRequirements(element.availableStaff, flightRequirements.requiredStaff) );
  });
}

displayStaffStatus();

 

 

출처: codecademy