module.exports 、 exports 和 export 、 export default 、 import
1:commonjs规范
module.exports={a:10,b:20}
var test=require('lib/test')
console.log(test.a);console.log(test.b); module.exports = function(name, age) {
this.name = name;
this.age = age;
this.about = function() {
console.log(this.name +' is '+ this.age +' years old');
};
};
var Rocker = require('./rocker.js');
var r = new Rocker('Ozzy', 62);
r.about(); module.exports.a=[1,2,3]
module.exports.b={a:10,b:20}
var test=require('lib/test')
console.log(test.a);console.log(test.b); exports.a={a:10,b:20}
注:module.exports优先有效,没有则将exports取到赋给module.exports 2:ES6规范
export var a=1
export function fun1(a,b){
return a+b
}
export const PI='3.1415925'
//export default每个文件只能有一个
export default {
a:10,
b:20
}
import('lib/utils') 动态加载 类似于commonjs的require('lib/utils')
import {a,b} from 'utils'
import * as utils from 'utils'
http://javascript.ruanyifeng.com/nodejs/module.html
http://es6.ruanyifeng.com/#docs/module
补充:如果要import的文件使用export default导出,直接import utils from "@/lib/utils"即可
原文地址:http://www.cnblogs.com/JimmyBright/p/7326848.html
module.exports 、 exports 和 export 、 export default 、 import的更多相关文章
- module.exports,exports,export和export default,import与require区别与联系【原创】
还在为module.exports.exports.export和export default,import和require区别与联系发愁吗,这一篇基本就够了! 一.首先搞清楚一个基本问题: modu ...
- module.exports,exports,export和export default,import与require区别与联系
还在为module.exports.exports.export和export default,import和require区别与联系发愁吗,这一篇基本就够了! 一.首先搞清楚一个基本问题: modu ...
- es6 import export 与 node 中的module.exports exports
1.export a.export 变量 export var name = 'jack';export var age = 18;//等同于 var name = 'jack';var age = ...
- module.exports exports 和export export default
首先可以知道的是这是两组不同模块规范. module.exports 是CommonJS模块规范,通过require 导入 a.js: var x = 'hello' module.exports.x ...
- exports module.exports export export default之间的关系
exports 和module.exports是CommonJS模块规范 export export default是ES6模块的规范,两者完全是不同的概念. node应用由模块组成,采用的是Comm ...
- NodeJS的exports、module.exports与ES6的export、export default深入详解
前言 决定开始重新规范的学习一下node编程.但是引入模块我看到用 require的方式,再联想到咱们的ES6各种export .export default. 阿西吧,头都大了.... 头大完了,那 ...
- 探索 模块打包 exports和require 与 export和import 的用法和区别
菜单快捷导航: CommonJS 之 exports和require用法 ES6 Module 之 export 和 import 用法 CommonJS和ES6 Module的区别 循环依赖 和 解 ...
- node.js module.exports & exports & module.export all in one
node.js module.exports & exports & module.export all in one cjs const log = console.log; log ...
- 你可以说出export export default || model.exports exports 的区别吗(一)
一.前言: 用模块写代码,为什么要用模块来写代码:ES6之前,在js中定义的一切,都是共享一个全局作用域的,随着web应用变得复杂,这样做会引起如:命名冲突和安全问题.于是引入了模块. 二.清楚一个概 ...
- require、module、exports dojo中的三个特殊模块标识
查看dojo源码过程中,发现这三个模块名并不以dojo.dijit.dojox开头,在dojo加载器中属于特殊模块名. require 这是一个上下文智能的加载器. 我们通过dojoConfig配置了 ...
随机推荐
- Linux 安装JDK Tomcat MySQL(使用Mac远程访问)
阅读本文需要一定的Linux基础 一 环境 阿里云服务器: CentOS 7.4 64位(基于RedHat) 本机: macOS High Sierra 二 压缩包 JDK http://www.or ...
- Web服务架构
# Web服务架构 ### Web服务模型-- 服务提供者.服务请求者.服务注册中心,服务注册中心是一个可选的角色. 现在的Web服务不仅限于WSDL,还有RESTful. - 服务提供者.即Web服 ...
- Hyperledger Fabric CA User’s Guide——CA用户指南(一)
Fabric CA用户指南 Hyperledger Fabric CA是一种用于Hyperledger Fabric的认证机构(CA). 它提供了如下特性: 登记身份(注册ID),或者连接到作为用户注 ...
- 基于神念TGAM的脑波小车(4)
我使用的是HC05和BT06俩个蓝牙模块 1.[AT模式]HC05蓝牙模块的PIO11接VCC,上电后即进入HC05AT指令模式,对于BT06蓝牙直接上电进入AT模式,用USBT06转TTL模块连接到 ...
- NIO基本概念
1. IO和NIO的区别 IO 面向流(stream oriented) 阻塞(blocking io) 无 NIO 面向缓冲区(buffer orie ...
- Nginx中server_name 参数详解
Nginx中的server_name指令主要用于配置基于名称的虚拟主机,server_name指令在接到请求后的匹配顺序分别为: 1.准确的server_name匹配,例如: server { lis ...
- webpack入门指南-step02
webpack 安装 1)安装前的准备:webpack是基于node环境的项目,所以使用前必须先安装node和npm. 在安装 Webpack 前,你本地环境需要支持 node.js.如果电脑没有装过 ...
- JS进阶系列之闭包
刚刚总结完作用域链,我觉得很有必要马上对闭包总结一下,因为,之前也写过自己对闭包的理解,那时候只知道,闭包就是可以访问别的函数变量的函数,就是在函数里面的函数就叫做闭包,可是并没有深入探究,为什么,可 ...
- 第二阶段Sprint1
昨天:进行第二阶段第一次站立会议,讨论冲刺阶段,目标,任务认领 今天:实现视频录制,共享平台的视频下载和上传 遇到的问题:调手机摄像头没问题,共享平台怎么办
- C#窗体——四则运算
用户需求:程序能接收用户输入的整数答案,并判断对错程序结束时,统计出答对.答错的题目数量.补充说明:0——10的整数是随机生成的用户可以选择四则运算中的一种用户可以结束程序的运行,并显示统计结果.在此 ...