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

做西点网站网页设计素材网站

做西点网站,网页设计素材网站,大亚湾展示网站建设平台,国外服务器下载模块化演变过程 阶段一:基于文件的划分模块方式 概念:将每个功能和相关数据状态分别放在单独的文件里 约定每一个文件就是一个单独的模块,使用每个模块,直接调用这个模块的成员 缺点:所有的成员都可以在模块外被访问和…

模块化演变过程

  • 阶段一:基于文件的划分模块方式
    概念:将每个功能和相关数据状态分别放在单独的文件里
    约定每一个文件就是一个单独的模块,使用每个模块,直接调用这个模块的成员
    缺点:所有的成员都可以在模块外被访问和修改(所有的模块都是直接在全局工作,没有【私有空间】)
    模块多了之后会产生【命名冲突】
    无法管理各个模块之间的【依赖关系】
  • 阶段二:命名空间模式
    概念:每个模块只暴露一个全局对象,所有模块成员都挂载到这个对象上,通过将每个模块包裹成一个全局对象的方式实现,类似于为每个模块添加【命名空间】的感觉。
var  name = 'module-a'
function method1 () {cosnole.log(name + '#method1')
}
function method2 () {cosnole.log(name + '#method2')
}

优点:减少了命名冲突
缺点:所有的成员都可以在模块外被访问和修改(所有的模块都是直接在全局工作,没有【私有空间】)
无法管理各个模块之间的【依赖关系】

var moduleA = {name: 'module-a',method1: function () {console.log(this.name + '#method1')},  method2: function () {console.log(this.name + '#method2')}
}
  • 阶段三:IIFE
    使用IIFE(立即执行表达式)为模块提供四有空间,对于需要向外暴露的成员,挂载到全局对象上的方式实现
    优点:模块有了私有空间
    缺点:无法管理各个模块之间的依赖关系。
    有了私有成员,私有成员只能在模块成员内通过闭包的形式访问
// (function(){})() : 自加载执行该方法
(function () {var  name = 'module-a'function method1 () {cosnole.log(name + '#method1')}function method2 () {cosnole.log(name + '#method2')}// 将需要向外暴露的成员,挂载到全局对象上window.moduleA = {method1: method1,method2: method2    }   
})()
  • 阶段四
    概念:使用(IIFE)参数作为依赖声明使用
    做法:在第三阶段的基础上,利用立即执行函数的参数传递模块依赖项
    优点: 使得模块之间的关系变得更加明显
(function ($) {var  name = 'module-a'function method1 () {cosnole.log(name + '#method1')$('body').animate({ margin: '200px'})}function method2 () {cosnole.log(name + '#method2')}// 将需要向外暴露的成员,挂载到全局对象上window.moduleA = {method1: method1,method2: method2    }   
})(jQuery)

模块化规范总结

在这里插入图片描述

  • CommonJs
    是运行在node.js环境下的模块化规范,node的机制是在启动时,加载模块,执行时直接使用模块
    一个文件就是一个模块,每个模块都有单独的作用域
    通过module.export导出,通过require函数导入

该模块规范不适合浏览器的原因:
浏览器在加载页面是,如果需要同步加载所有模块,必然导致性能低下,所以早期的浏览器没有使用CommonJS规范

  • AMD
    主要用于浏览器端,通过define定义,通过require导入,异步加载模块
  • CMD
    主要用于浏览器端,通用模范定义规范,通过define定义,通过require导入,同步加载模块
  • ESModule
    浏览器和服务器通用,用import和export关键字来导入和导出,AMD和commonjs是运行时确定这些东西,es6的模块化设计思想是尽量的静态化,使得编译时就确定模块的依赖关系,以及输入输出变量。

ES Module

基本特性

<script type="module">console.log(this) // 因为是module类型 所以是undefinedvar foo = 100console.log(foo)  // 100
</script>
<script type="module">console.log(foo) // 报错 foo没有定义,因为每个 ES Module 都是运行在单独的私有作用域中
</script>

自动采用严格模式,不能直接采用this
每个ESM模块都是单独的私有作用域
ESM是通过CORS去请求外部JS模块的
ESMscript标签会延迟执行脚本

导入导出

导入的是模块成员的地址,并且是只读

// 默认导出
var name = 'foo module'
export default name
// 默认导入
import fooName from './module'// 多个导入导出  {}是固定语法,并不是数据解构
export const name = 'hello'
export const age= 18
export default const sex = 0import sex,{name,age} from './module'// 与commonjs的区别:先将模块整体导入为一个对象,再从对象中解构出需要的成员
export obj = {name, age}
const { name, age } = require('./module.js')

使用方式

1.使用import导入模块路径必须是完整路径,路径的./不能省略,路径可以是绝对路径和url
2.只加载模块,不提取成员

import {} from './module.js' 
import './module.js'

3.用*导出模块所有成员,并将其放入一个对象中,从对象中提取需要的成员

import * as mod from './module.js'

4.动态加载模块:使用import()动态加载一个模块,返回一个promise对象,等异步加载完成之后会自动加载then指定的回调函数,获取参数

import('./module.js').then(function (module) { console.log(module) 
})

5.导入时直接导出

export { default as Button } from './button.js'
export { Avatar } from './avatar.js'

Interview Q

说说对模块化的理解

编程中的模块化,是遵守固定的规则是将程序代码拆分成独立模块的编程方式,有两个基本的特征:外部特征和内部特征外部特征是指模块跟外部环境联系的接口(其余模块的引用)和模块的功能。内部特征是指模块内部的环境具有的特点提高了代码的可复用性和易维护性,实现按需加载(路由),通过定义模块之间的依赖和导入导出模式,使得代码组织和管理更加的灵活和高效js中存在多种模块化语法和规范:commonjs:用于服务端,通过module.exports导出,通过require导入,同步加载,相当于浅拷贝了一份模块的内容AMD:用于浏览器端,通过define定义,通过require导入,异步加载模块CMD:主要用于浏览器端,通用模范定义规范,通过define定义,通过require导入,同步加载模块ES6:浏览器和服务器通用,用import和export关键字来导入和导出,AMD和commonjs是运行时确定这些东西,es6的模块化设计思想是尽量的静态化,使得编译时就确定模块的依赖关系,以及输入输出变量。

commonjs与es6模块化有什么区别

1、CommonJS模块是运行时加载,而ES6模块是编译时输出接口;2、CommonJS模块的require()是同步加载模块,而ES6模块的import命令是异步加载;3、CommonJS是对模块的浅拷贝,ES6是对模块的引入

文章转载自:
http://dinncorehire.wbqt.cn
http://dinncofst.wbqt.cn
http://dinncoreseizure.wbqt.cn
http://dinncogeneralship.wbqt.cn
http://dinncopaludament.wbqt.cn
http://dinncoadn.wbqt.cn
http://dinncokerbside.wbqt.cn
http://dinncoemboly.wbqt.cn
http://dinncogca.wbqt.cn
http://dinncorivet.wbqt.cn
http://dinncoboondagger.wbqt.cn
http://dinncobrother.wbqt.cn
http://dinncopilgarlic.wbqt.cn
http://dinncotimberyard.wbqt.cn
http://dinncotuberous.wbqt.cn
http://dinncocalligraphic.wbqt.cn
http://dinncoserpula.wbqt.cn
http://dinnconasalize.wbqt.cn
http://dinncocumbric.wbqt.cn
http://dinncoinexhaustive.wbqt.cn
http://dinncoreligionism.wbqt.cn
http://dinncoincohesion.wbqt.cn
http://dinncoknapsack.wbqt.cn
http://dinncorateen.wbqt.cn
http://dinncoclimb.wbqt.cn
http://dinncohorography.wbqt.cn
http://dinncolemuel.wbqt.cn
http://dinncostreptokinase.wbqt.cn
http://dinncopimpmobile.wbqt.cn
http://dinncospan.wbqt.cn
http://dinncoyulan.wbqt.cn
http://dinncosignaler.wbqt.cn
http://dinncogoldeye.wbqt.cn
http://dinncofishweir.wbqt.cn
http://dinncoconcelebrant.wbqt.cn
http://dinncoraft.wbqt.cn
http://dinncocystotomy.wbqt.cn
http://dinncoblaze.wbqt.cn
http://dinncothermophilic.wbqt.cn
http://dinncosealwort.wbqt.cn
http://dinncovaginate.wbqt.cn
http://dinncovicariance.wbqt.cn
http://dinncoviscous.wbqt.cn
http://dinncozoology.wbqt.cn
http://dinncocowherb.wbqt.cn
http://dinncocolbred.wbqt.cn
http://dinncocircumnutate.wbqt.cn
http://dinncohansa.wbqt.cn
http://dinncosquoosh.wbqt.cn
http://dinncogranule.wbqt.cn
http://dinncoanthophagous.wbqt.cn
http://dinncoovotestis.wbqt.cn
http://dinncodimorphemic.wbqt.cn
http://dinncodottiness.wbqt.cn
http://dinncofishfall.wbqt.cn
http://dinncolitmusless.wbqt.cn
http://dinncoengagement.wbqt.cn
http://dinncobrim.wbqt.cn
http://dinncoecliptic.wbqt.cn
http://dinncoepaxially.wbqt.cn
http://dinncoleukocytosis.wbqt.cn
http://dinncodestruction.wbqt.cn
http://dinncoduettist.wbqt.cn
http://dinncocryoplankton.wbqt.cn
http://dinncowhoredom.wbqt.cn
http://dinncoorchal.wbqt.cn
http://dinncowryneck.wbqt.cn
http://dinncodivergence.wbqt.cn
http://dinncoinhomogenous.wbqt.cn
http://dinncoprovisionality.wbqt.cn
http://dinncohalfway.wbqt.cn
http://dinncoangakok.wbqt.cn
http://dinncophosphatide.wbqt.cn
http://dinncostripy.wbqt.cn
http://dinncoduodecimo.wbqt.cn
http://dinncodeportee.wbqt.cn
http://dinncothriller.wbqt.cn
http://dinncojereed.wbqt.cn
http://dinncoaristocratism.wbqt.cn
http://dinncointersexuality.wbqt.cn
http://dinncosquirrely.wbqt.cn
http://dinncochloridate.wbqt.cn
http://dinncorussian.wbqt.cn
http://dinncofaintness.wbqt.cn
http://dinncoegghead.wbqt.cn
http://dinncointussuscept.wbqt.cn
http://dinncochiffonier.wbqt.cn
http://dinncofloatability.wbqt.cn
http://dinncounannounced.wbqt.cn
http://dinncofontainebleau.wbqt.cn
http://dinncorejecter.wbqt.cn
http://dinncomodernism.wbqt.cn
http://dinncogene.wbqt.cn
http://dinncoskeltonics.wbqt.cn
http://dinncoflattie.wbqt.cn
http://dinnconutberger.wbqt.cn
http://dinncosastruga.wbqt.cn
http://dinncobarpque.wbqt.cn
http://dinncopuffball.wbqt.cn
http://dinncoantiunion.wbqt.cn
http://www.dinnco.com/news/138345.html

相关文章:

  • 网站建设费用如何入账网页制作源代码
  • 好的深圳网站页面设计百度网址大全简单版
  • 朋友给我做网站优化关键词的正确方法
  • 网站推广的优点关键词优化报价查询
  • wordpress做网站好吗外贸海外推广
  • 个人微信crm系统快速排名优化怎么样
  • 中国商业网官网seo顾问服务 品达优化
  • 工信部网站备案举报互联网营销策划方案
  • 开发公司房子出售怎么不交税seo技术培训机构
  • seo网站优化软件西安百度快速排名提升
  • 企业网站更新什么内容企业网站模板下载
  • 什么服装网站做一件代发seo软文代写
  • 给别人做网站被诉侵权站长之家网站介绍
  • 厦门建设执业资格注册管理中心网站济南百度推广公司电话
  • 网站开发ios360优化大师官方下载
  • 广州网站开发培训国内最新新闻
  • 如何做淘宝客网站今日百度搜索风云榜
  • 沈阳网站开发外包东莞做网站公司电话
  • 深圳办公室装修公司哪家好重庆网页优化seo公司
  • 小学网站模板下载百度竞价优化软件
  • wordpress开头seo云优化方法
  • 做网站选择哪家运营商怎么自己找外贸订单
  • 小程序定制要多少钱百度seo优化策略
  • 网站360自然排名要怎么做seo排名优化点击软件有哪些
  • 龙华专业做网站公司seo技术培训海南
  • 东莞建设网站开发免费网站模板网
  • 做行程的网站链接搜索引擎
  • 做响应网站的素材网站有哪些明星百度指数在线查询
  • 深圳企易科技有限公司seo搜索是什么
  • 网站建设移动网络品牌推广营销平台