当前位置:网站首页>ES6 modular
ES6 modular
2022-07-16 05:54:00 【Like to drink pearl milk tea】
Tips : When the article is finished , Directories can be generated automatically , How to generate it, please refer to the help document on the right
1. Modular classification
ES6 The introduction of modularity , Its design idea is to be able to determine the dependency of modules at compile time , And the input and output variables .
ES6 The modularization of is divided into export (export) And Import (import) Two modules .
2. Modular features
(1)ES6 The module automatically turns on strict mode , Whether you have Add use strict;.
(2) Various types of variables can be imported and exported in the module , Such as function , object , character string , Numbers , Boolean value , Class etc. .
(3) Each module has its own context , The variables declared in each module are local variables , Does not contaminate the global scope .
(4) Each module is loaded only once ( Is a singleton ), If you load the same file in the same directory , Read directly from memory .
3.export export
And default Associated use , And one js Module There can only be one export default sentence
var obj={name:"karen"}
export var num=100
export function tool () {return obj}
// Separately exported The exported identifier must be used to import on demand , There can be multiple separate exports
// The default is derived There can only be one or... In this file 0 individual
var a=20
var arr=[100,203,4]
var fm=()=>{}
export default {a,arr,fm,num,tool}
4.import Import
And from Associated use , here script Labeled type Must be set to module
The singleton pattern : Repeat the same sentence several times import sentence , that It's only going to be executed once , It's not executed many times .import The same module , Declare different interface references , Will declare the corresponding variable , But only once import
give an example :
<script type="module">
import People from './js/myModule.js';
let p = new People();
p.say();
</script>5. hold js Script written in the page 3 Ways of planting
1. Inline :js The engine is going to execute some of the tags ( event ) Properties of the
2. The embedded
3. Import src My address is a js The path of Will load js code (jsonp)
6. Introduce on demand 、 Import on demand
import x,{num,tool} from "./src/model1.js"
console.log(num)
console.log(tool)
console.log(obj)
var re=tool()
console.log(re)
console.log(x.arr)
import {tool} from "./src/model1.js"
import x from "./src/model1.js"
x.tool
import Hq from './src/model1.js'
console.log(Hq.Photo)
import {Photo as a} from './src/model1.js'
let a=Photo
console.log(Photo.name)
边栏推荐
猜你喜欢

window系统盘瘦身(开发)
![[BJDCTF2020]Cookie is so stable](/img/d8/fb9fc2496ee8b23ec6fd6195051030.png)
[BJDCTF2020]Cookie is so stable

Network security emergency response - electronic data forensics technology

内网渗透笔记——二层发现

win10下测试mysql主从同步

Log blacklist can really save you money!

BUUCTF 荷兰宽带数据泄露

Memory forensics - installation and use of volatility and some CTF competition topics

ES6 -- let and Const

使用百度轻量服务器LS遇到的一些小问题
随机推荐
Hand to hand teaching - using native POI to import and export excel and the basic operations of Alibaba's easyexcel
[Huang ah code] getting started with MySQL - 2. Using data definition language (DDL) to operate the database
[Huang ah code] getting started with MySQL - 1. SQL execution process
Intranet penetration notes - Sticky Keys and system command information collection
Buuctf webshell back door
模块化-CMJ&ESM
Notes - Chang Geng
Memo, usememo, usecallback summary
Php+jmeter simulates high concurrency scenarios. Code attached.
JS收官笔记
Js-- written examination questions (set)
[安洵杯 2019]easy_web
网络安全应急响应-基础技能
ES6 -- let and Const
服务器对接码云webhooks实现自动部署--超详细--PHP
Create / delete tablespaces / users
Intranet penetration notes --:) a smiling face
Some small problems encountered in using Baidu lightweight server LS
《自动化机器学习》
PLSQL problem solving ora-12154: tns: unable to resolve the specified connection identifier


