In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-03-10 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)05/31 Report--
This article mainly explains "how to use import as in es6". Interested friends may wish to have a look at it. The method introduced in this paper is simple, fast and practical. Let's let the editor learn how to use import as in es6.
In es6, import as is used to combine the contents of several export exports into an object to return; the modularization of ES6 is divided into two modules: export and import, this method can wrap all the exported contents into the specified object, and the syntax is "import * as object from."
This tutorial operating environment: windows10 system, ECMAScript version 6. 0, Dell G3 computer.
What is the use of import as in es6
ES6,javascript supports module for the first time. The modularization of ES6 is divided into two modules: export and import. In the project, we often see the use of import * as obj from, which wraps all the output in an obj object.
Import * as xxx from 'xxx': will combine the contents of several export exports into one object to return
Import xxx from 'xxx': (export default Din) will only export this default object as an object
Example one
/ / index.jsexport function fn1 (data) {console.log (1)} export function fn2 (data) {console.log (2)} import * as Fn from'. / index.js'Fn.fn1 () / / 1Fn.fn2 () / / 2
Example two
Let myName = "Jon"; let myAge = 18 myName as name myfn = function () {return "I am" + myName+ "!" + myAge+ "this year"} export {myName as name, myAge as age, myfn as fn}
Received code
Import {fn,age,name} from ". / test.js"; console.log (fn ()); / / I'm Jon! He is 19 years old. Console.log (age); / / 19console.log (name); / / Jon
Or write it as
Import * as info from ". / test.js"; / / batch receive through *, as to specify the name of the receive console.log (info.fn ()); / / I am Jon! 18-year-old console.log (info.age); / / 18console.log (info.name); / / Jon
Example three
Rename export and import. If you import multiple files with the same variable name, there will be a naming conflict. In order to solve this problem, ES6 provides a renaming method, which you can do when importing names.
/ * test1.js*/export let myName = "I'm from test1.js"; / * test2.js*/export let myName = "I'm from test2.js" / * index.js*/import {myName as name1} from ". / test1.js"; import {myName as name2} from ". / test2.js"; console.log (name1); / / I come from test1.jsconsole.log (name2) / / I am from test2.js here. I believe you have a better understanding of "how to use import as in es6". You might as well do it in practice. Here is the website, more related content can enter the relevant channels to inquire, follow us, continue to learn!
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.