ECMAScript Cookbook
上QQ阅读APP看书,第一时间看更新

How to do it...

  1. Copy the folder created for the previous recipe into a new directory.
  2. Navigate to that directory with your command-line application and start the Python server.
  1. Rename rocket.js to saturn-v.js, add the name of the rocket to the log statements, and update the main.js import statement:

// main.js import name, { launch, COUNT_DOWN_DURATION } from './saturn-v.js'; export function main () { console.log('This is a "%s" rocket', name); console.log('It will launch in "%d" seconds.', COUNT_DOWN_DURATION); launch(); }
// saturn-v.js export function launch () { console.log(`Launching %s in ${COUNT_DOWN_DURATION}`, name); launchSequence(); } function launchSequence () { // . . . console.log(%shas LIFTOFF!!!', name); // . . . }

  1. Copy saturn-v.js to a new file named falcon-heavy.js and change the default export value and the COUNT_DOWN_DURATION:
    export default name = "Falcon Heavy";
    export const COUNT_DOWN_DURATION = 5;  
  1. Import the falcon module into main.js. Rename the imported members to avoid conflicts and launch the falcon rocket as well:
import rocketName, { launch, COUNT_DOWN_DURATION } from './saturn-v.js'; 
import falconName, { launch as falconLaunch, COUNT_DOWN_DURATION as falconCount } from './falcon-heavy.js'; 
 
export function main () { 
  console.log('This is a "%s" rocket', rocketName); 
  console.log('It will launch in  "%d" seconds.', COUNT_DOWN_DURATION); 
  launch(); 
   
  console.log('This is a "%s" rocket', falconName);  console.log('It will launch in  "%d" seconds.', falconCount);  falconLaunch(); 
} 
  1. Open index.html in your browser and you should see the following output: