Study
-
Import Named ImportsStudy/JavaScript 2020. 5. 14. 19:19
Import Named Imports To import variables that are declared, we simply use the original syntax that describes the variable name. In other words, exporting upon declaration does not have an impact on how we import the variables. import { specialty, isVegetarian } from 'menu'; import {availableAirplanes, flightRequirements, meetsStaffRequirements,meetsSpeedRangeRequirements} from './airplane'; func..
-
Export Named ExportsStudy/JavaScript 2020. 5. 14. 18:59
Export Named Exports Named exports are also distinct in that they can be exported as soon as they are declared, by placing the keyword export in front of variable declarations. In menu.js export let specialty = ''; export function isVegetarian() { }; function isLowSodium() { }; The export keyword allows us to export objects upon declaration, as shown in export let specialty and export function i..
-
Named ExportsStudy/JavaScript 2020. 5. 14. 18:00
Named Exports ES6 introduced a second common approach to export modules. In addition to export default, named exports allow us to export data through the use of variables. Let’s see how this works. In menu.js we would be sure to give each piece of data a distinct variable name: let specialty = ''; function isVegetarian() { }; function isLowSodium() { }; export { specialty, isVegetarian }; Notice..
-
importStudy/JavaScript 2020. 5. 14. 17:40
import ES6 module syntax also introduces the import keyword for importing objects. In our order.js example, we import an object like this: import Menu from './menu'; The import keyword begins the statement. The keyword Menu here specifies the name of the variable to store the default export in. from specifies where to load the module from. './menu' is the name of the module to load. When dealing..
-
export defaultStudy/JavaScript 2020. 5. 14. 17:12
export default Node.js supports require()/module.exports, but as of ES6, JavaScript supports a new more readable and flexible syntax for exporting modules. These are usually broken down into one of two techniques, default export and named exports. We’ll begin with the first syntax, default export. The default export syntax works similarly to the module.exports syntax, allowing us to export one m..
-
module.exports IIStudy/JavaScript 2020. 5. 14. 17:01
module.exports II We can also wrap any collection of data and functions in an object, and export the object using module.exports. In menu.js, we could write: module.exports = { specialty: "Roasted Beet Burger with Mint Sauce", getSpecialty: function() { return this.specialty; } }; In the above code, notice: module.exports exposes the current module as an object. specialty and getSpecialty are pr..
-
require()Study/JavaScript 2020. 5. 14. 16:47
require() To make use of the exported module and the behavior we define within it, we import the module into another file. In Node.js, use the require() function to import modules. For instance, say we want the module to control the menu’s data and behavior, and we want a separate file to handle placing an order. We would create a separate file order.js and import the Menu module from menu.js to..
-
module.exportsStudy/JavaScript 2020. 5. 14. 16:29
module.exports We can get started with modules by defining a module in one file and making the module available for use in another file with Node.js module.exports syntax. Every JavaScript file run in Node has a local module object with an exports property used to define what should be exported from the file. Below is an example of how to define a module and how to export it using the statement ..