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

网站权重什么意思织梦网站图片移动

网站权重什么意思,织梦网站图片移动,工地用的木模板是什么板,网站页脚有什么作用1. 介绍 1.1 什么是模块化与模块 ? 将一个复杂的程序文件依据一定规则(规范)拆分成多个文件的过程称之为 模块化其中拆分出的 每个文件就是一个模块 ,模块的内部数据是私有的,不过模块可以暴露内部数据以便其他模块使用 1.2 什…

1. 介绍

1.1 什么是模块化与模块 ?

  • 将一个复杂的程序文件依据一定规则(规范)拆分成多个文件的过程称之为 模块化
  • 其中拆分出的 每个文件就是一个模块 ,模块的内部数据是私有的,不过模块可以暴露内部数据以便其他模块使用

1.2 什么是模块化项目 ?

编码时是按照模块一个一个编码的, 整个项目就是一个模块化的项目

1.3 模块化好处

下面是模块化的一些好处:

  1. 防止命名冲突
  2. 高复用性
  3. 高维护性

2. 模块暴露数据

2.1 模块初体验

可以通过下面的操作步骤,快速体验模块化

  1. 创建 me.js
//声明函数
function tiemo(){console.log('贴膜....');
}
//暴露数据
module.exports = tiemo;
  1. 创建 index.js
//导入模块
const tiemo = require('./me.js');
//调用函数
tiemo();

2.2 暴露数据

模块暴露数据的方式有两种:

  1. module.exports = value
  2. exports.name = value

使用时有几点注意:

  • module.exports 可以暴露 任意 数据
  • 不能使用 exports = value的形式暴露数据,模块内部 module 与 exports 的隐式关系exports = module.exports = {},require 返回的是目标模块中 module.exports 的值

在这里插入图片描述

2.3 暴露数据 案例

2.3.1 me.js

//声明一个函数
function tiemo(){console.log('贴膜...');
}//捏脚
function niejiao(){console.log('捏脚....');
}//暴露数据
// module.exports = {
//   tiemo,
//   niejiao
// }// exports 暴露数据
// exports.niejiao = niejiao;
// exports.tiemo = tiemo;//1. module.exports 可以暴露`任意`数据
// module.exports = 'iloveyou';
// module.exports = 521;//2. 不能使用 `exports = value`的形式暴露数据
// exports = 'iloveyou' // X// exports = module.exports = {}
// console.log(module.exports);
// console.log(module.exports === exports);exports = module.exports = {tiemo:tiemo}
exports.tiemo = tiemo;
// exports = 'iloveyou' // X

2.3.2 index.js

//导入模块
const me = require('./me.js');//输出 me
console.log(me);
// me.tiemo();
// me.niejiao();

3. 导入(引入)模块

在模块中使用 require 传入文件路径即可引入文件
const test = require('./me.js');

3.1 require 使用的一些注意事项

  1. 对于自己创建的模块,导入时路径建议写 相对路径 ,且不能省略 ./…/
  2. jsjson 文件导入时可以不用写后缀,c/c++编写的 node 扩展文件也可以不写后缀,但是一般用不到
  3. 如果导入其他类型的文件,会以 js 文件进行处理
  4. 如果导入的路径是个文件夹,则会 首先 检测该文件夹下 package.json 文件中 main 属性对应的文如果存在则导入,反之如果文件不存在会报错。如果 main 属性不存在,或者package.json 不存在,则会尝试导入文件夹下的 index.jsindex.json ,如果还是没找到,就会报错
  5. 导入 node.js 内置模块时,直接 require 模块的名字即可,无需加 ./…/

3.2 导入模块 案例

3.2.1 duanzi.js

module.exports = '我是个段子';

3.2.2 duanzi.json

{"text": "有一天北极熊打电话给企鹅,问他为什么每次约他去看电影他都不去?为什么啊?企鹅回答到,我他妈太南了。","name": "曹小俊吖","id": 1
}

3.2.3 index.js

//导入模块  // fs 
// const tiemo = require('./me.js');//省略后缀 JS
// const tiemo = require('./me');//导入 JSON 文件
// const duanzi = require('./duanzi');
// console.log(duanzi);//对象//导入其他类型的文件
const test = require('./test');console.log(test);
// //调用函数
// tiemo();

3.2.4 me.js

//声明一个函数
function tiemo(){console.log('贴膜...');
}//暴露数据
module.exports = tiemo;

4. 导入模块的基本流程

require 导入 自定义模块 的基本流程

  1. 将相对路径转为绝对路径,定位目标文件
  2. 缓存检测
  3. 读取目标文件代码
  4. 包裹为一个函数并执行(自执行函数)。通过arguments.callee.toString()查看自执行函数
  5. 缓存模块的值
  6. 返回 module.exports的值

在这里插入图片描述
在这里插入图片描述

4.1 导入文件夹 案例

在这里插入图片描述

4.1.1 app.js

module.exports = '我是一个模块';

4.1.2 main.js

//导入
const m = require('./module');console.log(m);

5. CommonJS 规范

module.exportsexports以及 require这些都是 CommonJS模块化规范中的内容。
而 Node.js 是实现了 CommonJS 模块化规范,二者关系有点像 JavaScript 与 ECMAScript

6. require 案例

6.1 me.js

const test = {name: '尚硅谷'
}module.exports = test;//输出
// console.log(arguments.callee.toString());
console.log(test);

6.2 show.js

/*** 伪代码*/function require(file){//1. 将相对路径转为绝对路径,定位目标文件let absolutePath = path.resolve(__dirname, file);//2. 缓存检测if(caches[absolutePath]){return caches[absolutePath];}//3. 读取文件的代码let code = fs.readFileSync(absolutePath).toString();//4. 包裹为一个函数 然后执行let module = {};let exports = module.exports = {};(function (exports, require, module, __filename, __dirname) {const test = {name: '尚硅谷'}module.exports = test;//输出console.log(arguments.callee.toString());})(exports, require, module, __filename, __dirname)//5. 缓存结果caches[absolutePath] = module.exports;//6. 返回 module.exports 的值return module.exports;
}const m = require('./me.js');

6.3 index.js

//导入 me.js
const m = require('./me.js');
const m2 = require('./me.js');
http://www.yayakq.cn/news/205907/

相关文章:

  • 成寿寺网站建设公司新闻投稿平台
  • 怎么建设物流网站企业网站营销的典型案例
  • 全国建设管理信息网站怎样把自己的网站进行推广
  • 专业建设外贸网站宾爵手表官方网站
  • 买软件的网站建设wordpress 搭建电商
  • 网站建设代码走查百度竞价平台官网
  • 泰州网站建设工作建设企业网站官网下载中心
  • 做网站如何挂支付系统利用大平台做网站
  • 申请摇号广州网站网络营销环境的分析主要是
  • 东莞ppt免费模板下载网站淘宝客推广有效果吗
  • 嘉兴网站制作软件有网站加金币的做弊器吗
  • 朋友圈网站文章怎么做wordpress破解主题
  • 外贸网站建设销售常用语wordpress采集站
  • 020网站设计来几个好看的网站
  • 那个企业网站是用vue做的做推广有什么好网站
  • 寺庙招人做网站维护吗wordpress怎么搜站点
  • 策划对于企业网站建设来说深圳企业网站建设企业
  • 优购物官方网站订单查询介绍一学一做视频网站
  • 广州网站关键词推广手机创建自己网站
  • 服务器用来做网站和数据库平面设计论坛有哪些
  • 达建网站的需要企业展厅建设公司
  • 彩票网站开发dadi163大型网站如何优化
  • 建一个网站需要多少时间表西安网站维护
  • 集团网站群建设方案安徽建设工程协会网站
  • 和县网站制作商务网站建设的第一步
  • 企业网站建设规划方案安徽安庆中考成绩查询
  • 网站吗节省空间的装修设计
  • 公司做网站广告语内蒙古工程建设网站
  • 网站开发量计算网站模板带后台下载
  • 小说网站怎么做appWordPress搭建交互式网站