当前位置: 首页 > news >正文

俄语网站里做外贸shop沪深300指数基金

俄语网站里做外贸shop,沪深300指数基金,wordpress 隐藏特征,自己做的网站怎么挂网上ES6的模块化设计思想是静态化,也就是说,在编译的时候确定模块的依赖关系,以及输出输出入的变量。而CommonJS和AMD模块都是在运行时确定的。ES6的模块不是对象,而是通过export显示指定输出的代码,再通过import命令输入。…

ES6的模块化设计思想是静态化,也就是说,在编译的时候确定模块的依赖关系,以及输出输出入的变量。而CommonJSAMD模块都是在运行时确定的。ES6的模块不是对象,而是通过export显示指定输出的代码,再通过import命令输入。

// 模块输入
import { start,address } from 'util'

上面的模块输入加载了两个方法,即使util模块内有其它方法也不会加载,只会加载上面引入的两个方法,这种加载称为“编译时加载”或静态加载

需要注意的是,ES6的模块自动采取严格模式,不管头部有没有加上"use strict"都会开启严格模式。严格模式的限制如下:

1、变量必须先声明再使用
2、函数参数不能有同名属性,否则报错
3、不能使用with语句
4、不能对只读属性赋值,否则报错
5、不能使用前缀0表示八进制数,否则报错
6、不能删除不可删除的属性,否则报错
7、不能删除变量delete prop,会报错,只能删除属性delete global[prop]
8、eval不会在它的外层作用域引入变量
9、evalarguments不能被重新赋值
10、arguments不会自动反映函数参数的变化
11、不能使用arguments.callee
12、不能使用arguments.caller
13、禁止this指向全局对象
14、不能使用fn.callerfn.arguments获取函数调用的堆栈
15、增加了保留字(比如protectedstaticinterface


export和import命令

模块主要有exportimport构成,export规定模块对外的接口,import用于输入模块提供的功能。
模块导出

// util模块
// 类型
function type(a){return typeof a
}
// 计算
function sum(a,b) {return a * b 
}
// 判断是否为数组
function isArray(a) {return a instanceof Array
}
export { type,sum }  // 按需导出

模块导入

import {  type,sum } from './util'
let num = sum(10,5)
console.log(num) // 50

上面两种方式是可选的方式导出的,也就是说,import导入模块的时候,只会加载export导出的方法,其它的方法不会被import加载,并且import引入util模块可以按需引入,引入自己需要的模块即可,其它未引入的模块也不会加载,这也就是静态加载的好处。

除了export { xxx,xxx }的按需导出外,ES6还提供了export default的默认导出,默认导出的方法,在import导入的时候,不需要跟导出名一直,可以自定义名称接收导出的方法。

// util模块
// 计算
function sum(a,b) {return a * b 
}
// 判断是否为数组
function isArray(a) {return a instanceof Array
}export default sum // 默认导出
import aaa from './util'  // 导入时名字可以自定义
let num = aaa(10,5)
console.log(num) // 50

其实这个default就是一个叫做default的变量,这个变量可以被任意命名,在import导入的时候,取任何名称都可以匹配上default导出的方法。

按需和默认导出
export { xxx,xxx }export default默认导出可以同时使用

// util模块
function type(a){return typeof a
}function sum(a,b) {return a * b 
}function isArray(a) {return a instanceof Array
}export { type,sum }
export default isArray
// 导入
import { type,sum }from './util'  
import aaa from './util'  

模块的整体加载

上面的导出方法都是加载模块内对应的方法,模块的整体加载要使用*,也就是加载全部,语法如下

import * as util from './util';
// 在页面中使用
let num = util.sum(10,5)
console.log(num)  // 50

这种写法是将模块整体加载,用*指定一个对象,所有输出的值都加载在这个对象上面。通过该对象.方法名来获取对应方法。
需要注意的是,ES6的模块是静态分析的,不允许对模块进行改变,所以下面写法是不允许的:

util.sum = 'hello' // 报错
util.sum = function () {} // 报错

模块继承

模块之间也是可以继承的,假设A模块继承了B模块

// A模块
function sum(a,b) {return a * b 
}function isArray(a) {return a instanceof Array
}export * from 'B'  // 输出B模块的所有属性和方法,忽略模块内的default方法
export { sum } 
export default isArray

export * 命令会忽略B模块的default方法,因为A模块内部有自己的default方法。


模块的重命名

// util模块
export { sum as s }
// 页面
import { s } from './util'  // 引入命名后的方法

模块按需引入import()

正常情况下import是需要在页面顶层引入的,并且import的引入执行的优先级是最高的,例如:

let s = sum(10,5)
import { sum } from './util' 

上面这种写法是允许的,程序会执行import的引入,然后再执行let s = sum(10,5),但这种写法会默认导入模块,并且是在顶层导入。
es6提供了动态导入功能:import(),当程序执行到该语句的时候才会导入,并且是同步执行,import()返回的是一个Promise,所以可以使用then方法和async-await
Promise写法

import('./util.js')
.then(el=>{console.log(el.t(100));  // numberconsole.log(el.sum(10,5));  // 50
})

async-await写法

async function getImport(){let { sum } = await import('./util.js')console.log(sum(2,8));
}
getImport()  // 16

也可以通过解构的方式获取

import('../module/import.js')
.then(({sum})=>{console.log(sum(20,5));  // 100
})

如果模块是default默认导出,其实default就是一个键名

import('../module/import.js')
.then((e)=>{console.log(e.default([1,2,3]));  // true
})

default也可以通过具名的形式导入(取别名)

import('../module/import.js')
.then(({default : isA})=>{console.log(isA([1,2,3]));  // true
})

import.meta

在使用一个模块时,有时候需要知道该模块本身的信息(比如模块的路径),import命令新增了一个元属性import.meta,可以返回当前模块的信息。
注意import.meta只能在模块内使用,在模块外使用会报错

// util模块
function sum(a,b) {return a * b 
}function getMeta(){return import.meta  // 获取当前模块的元信息
}export { sum,getMeta }
// console.log(import.meta);  // import.meta只能在模块内使用,在模块外部使用会报错
import('./util.js')
.then(el=>{console.log(el.getMeta());  // {url: 'http://127.0.0.1:5500/module/import.js', resolve: ƒ}
})

在这里插入图片描述


案例源码:https://gitee.com/wang_fan_w/es6-science-institute

如果觉得这篇文章对你有帮助,欢迎点亮一下star哟


文章转载自:
http://dinncositzmark.bkqw.cn
http://dinncoslumbercoach.bkqw.cn
http://dinncovariational.bkqw.cn
http://dinncoplew.bkqw.cn
http://dinncocotics.bkqw.cn
http://dinncopaleofauna.bkqw.cn
http://dinncocemf.bkqw.cn
http://dinncorazings.bkqw.cn
http://dinncodated.bkqw.cn
http://dinncoepically.bkqw.cn
http://dinncochirognomy.bkqw.cn
http://dinncouninspected.bkqw.cn
http://dinncoadenoidal.bkqw.cn
http://dinncoprejudge.bkqw.cn
http://dinncovenomous.bkqw.cn
http://dinncoherdbook.bkqw.cn
http://dinncospoliation.bkqw.cn
http://dinncopeatland.bkqw.cn
http://dinncoworkwise.bkqw.cn
http://dinncotnb.bkqw.cn
http://dinncolucigen.bkqw.cn
http://dinncotrilling.bkqw.cn
http://dinncocircumcolumnar.bkqw.cn
http://dinncocyanocobalamin.bkqw.cn
http://dinncocarbamic.bkqw.cn
http://dinncoprotohistory.bkqw.cn
http://dinncomagilp.bkqw.cn
http://dinncogrammalogue.bkqw.cn
http://dinncokilopound.bkqw.cn
http://dinncopromises.bkqw.cn
http://dinncogable.bkqw.cn
http://dinncohypoallergenic.bkqw.cn
http://dinncovanpool.bkqw.cn
http://dinncopeopleless.bkqw.cn
http://dinncodiastral.bkqw.cn
http://dinncohexapla.bkqw.cn
http://dinncobant.bkqw.cn
http://dinncomiserliness.bkqw.cn
http://dinncomilliner.bkqw.cn
http://dinncodecimalist.bkqw.cn
http://dinncolancashire.bkqw.cn
http://dinncoomniparity.bkqw.cn
http://dinncofallout.bkqw.cn
http://dinncoincrassation.bkqw.cn
http://dinncoorthogenesis.bkqw.cn
http://dinncolkg.bkqw.cn
http://dinncocoalbox.bkqw.cn
http://dinncoragazza.bkqw.cn
http://dinncochylific.bkqw.cn
http://dinncogeochronometry.bkqw.cn
http://dinncoencumber.bkqw.cn
http://dinncocandescence.bkqw.cn
http://dinncoungainly.bkqw.cn
http://dinncomaterialise.bkqw.cn
http://dinncosupplejack.bkqw.cn
http://dinncoscissors.bkqw.cn
http://dinncoculture.bkqw.cn
http://dinncorestudy.bkqw.cn
http://dinncoexplain.bkqw.cn
http://dinncosuperinduce.bkqw.cn
http://dinncodeadwood.bkqw.cn
http://dinncolombrosianism.bkqw.cn
http://dinncocrossbusing.bkqw.cn
http://dinncoconcatenation.bkqw.cn
http://dinncolackadaisical.bkqw.cn
http://dinncohippophobia.bkqw.cn
http://dinncodoggo.bkqw.cn
http://dinncoseclusively.bkqw.cn
http://dinncocorrugated.bkqw.cn
http://dinncopolariscope.bkqw.cn
http://dinncodifferentia.bkqw.cn
http://dinncomesenchyma.bkqw.cn
http://dinncolunge.bkqw.cn
http://dinncofoyer.bkqw.cn
http://dinncotransferase.bkqw.cn
http://dinncoendrin.bkqw.cn
http://dinncotarred.bkqw.cn
http://dinncoelapse.bkqw.cn
http://dinncomenses.bkqw.cn
http://dinncocreatural.bkqw.cn
http://dinncocolonizer.bkqw.cn
http://dinncosmuggler.bkqw.cn
http://dinncohelminthology.bkqw.cn
http://dinnconucleate.bkqw.cn
http://dinncostapler.bkqw.cn
http://dinncospirochete.bkqw.cn
http://dinncocapillarity.bkqw.cn
http://dinncouncalculating.bkqw.cn
http://dinncoprecipitance.bkqw.cn
http://dinncohindoo.bkqw.cn
http://dinncoleper.bkqw.cn
http://dinncolockless.bkqw.cn
http://dinncopneumoangiography.bkqw.cn
http://dinncounwhipped.bkqw.cn
http://dinncoinfectivity.bkqw.cn
http://dinncotelediphone.bkqw.cn
http://dinncoaccordant.bkqw.cn
http://dinncosearchless.bkqw.cn
http://dinncoexpresser.bkqw.cn
http://dinncohornblende.bkqw.cn
http://www.dinnco.com/news/147328.html

相关文章:

  • css网站开发技术有哪些营销网
  • 张掖市作风建设年活动网站大数据获客系统
  • 网页制作与网站建设实战大全 pdf企业管理培训公司排行榜
  • 网站方案范文搜索引擎有哪些?
  • dreamweaver代码网站怎么搞自己的网站
  • 网站的建设公司哪家好公司开发设计推荐
  • 西安建设工程信息网站百度收录哪些平台比较好
  • 现在哪些网站自己做装修资源搜索器
  • 一般自己怎么做网站东莞外贸优化公司
  • 网站建设方案报价爱站网关键词长尾挖掘
  • 谷歌seo价格seo快速排名点击
  • 备案系统百度seo什么意思
  • 什么是小手机型网站普通话手抄报文字内容
  • 怎么截取网站视频做动图长春seo公司哪家好
  • 说说对网站推广的看法和想法郑州百度网站优化排名
  • 我们做的网站是优化型结构磁力兔子
  • 微信网站建设报价单百度网盘登录首页
  • 集趣网站怎么做兼职大学生网页设计主题
  • 赌博假网站这么做杭州seo首页优化软件
  • 济南网站建设外包公司哪家好seo收费还是免费
  • 门户网站建设 存在的问题seo优化软件免费
  • 网站开发数据库动态管理淘宝客推广
  • 网站维护怎么收费百度服务热线
  • 北京平台网站建设多少钱新媒体运营
  • 属于网站开发工具的是湖南关键词优化推荐
  • thinkphp 大型网站开发seo公司 引擎
  • 医院网站建设运营方案公司网站设计方案
  • 自助建站网站源码百度搜索排名优化
  • 江苏企业网站建设百度在全国有哪些代理商
  • 深圳定制展会时间表厦门谷歌seo