ABOUT ME

-

Today
-
Yesterday
-
Total
-
  • Combining Export Statements
    Study/JavaScript 2020. 5. 14. 20:18

    Combining Export Statements

    We can also use named exports and default exports together. In menu.js:

     

     

    let specialty = '';
    function isVegetarian() {
    }; 
    function isLowSodium() {
    }; 
    function isGlutenFree() {
    };
    
    export { specialty as chefsSpecial, isVegetarian as isVeg };
    export default isGlutenFree;

     

     

    Here we use the keyword export to export the named exports at the bottom of the file. Meanwhile, we export the isGlutenFree variable using the export default syntax.

    This would also work if we exported most of the variables as declared and exported others with the export default syntax.

     

    export let Menu = {};
    
    export let specialty = '';
    export let isVegetarian = function() {
    }; 
    export let isLowSodium = function() {
    }; 
    let isGlutenFree = function() {
    };
    
    export default isGlutenFree;

     

    Here we use the export keyword to export the variables upon declaration, and again export the isGlutenFree variable using the export default syntax

    While it’s better to avoid combining two methods of exporting, it is useful on occasion. For example, if you suspect developers may only be interested in importing a specific function and won’t need to import the entire default export.

     


    
     export let availableAirplanes = [
    {
      name: 'AeroJet',
      fuelCapacity: 800,
      availableStaff: ['pilots', 'flightAttendants', 'engineers', 'medicalAssistance', 'sensorOperators'],
      maxSpeed: 1200,
      minSpeed: 300
     }, 
     {name: 'SkyJet',
      fuelCapacity: 500,
      availableStaff: ['pilots', 'flightAttendants'],
      maxSpeed: 800,
      minSpeed: 200
     }
    ];
    
    
     export let flightRequirements = {
      requiredStaff: 4,
      requiredSpeedRange: 700
    };
    
     export function meetsStaffRequirements(availableStaff, requiredStaff) {
      if(availableStaff.length >= requiredStaff){
        return true;
      }else {
        return false;
      }
      }
    
    
    
     function meetsSpeedRangeRequirements(maxSpeed, minSpeed, requiredSpeedRange){
      let range = maxSpeed - minSpeed;
      if(range > requiredSpeedRange){
        return true;
      }else{
        return false;
      }
    }
    
    
    export default meetsSpeedRangeRequirements;

    'Study > JavaScript' 카테고리의 다른 글

    What is a Promise?  (0) 2020.05.15
    Introduction(promise)  (0) 2020.05.15
    Import as  (0) 2020.05.14
    Export as  (0) 2020.05.14
    Import Named Imports  (0) 2020.05.14

    댓글

Designed by Tistory.