1.export

  a.export 变量

export var name = 'jack';
export var age = 18;
//等同于
var name = 'jack';
var age = 18;
export {name,age};

  a.export 方法

export function sayHello(){
console.log('hello world!');
} //等同于
function sayHello(){
console.log('hello world!');
} export {sayHello};

2.import 

  import 与 export 正好相反;

import {name,age} from './exportTest.js';

console.log(name);
console.log(age); import {sayHello} from './exportTest.js'; sayHello();

3.default

默认导出的模块,每个js文件中只能有一个export default 。

正是因为export default命令其实只是输出一个叫做default的变量,所以它后面不能跟变量声明语句。

// 正确
export var a = ; // 正确
var a = ;
export default a; // 错误
export default var a = ;

export  default 可以导出一个方法:

export default function test() {
this.name = "jack";
};

由于export default,在import 的时候可以为其指定任意名字,因为default 本身是匿名的。

//正确
import test from './exportTest.js'; //正确
import myTest from './exportTest.js'; //正确
import hello from './exportTest.js';

4. module.exports 与 exports

module.exports ,exports 为node.js 的方法, module.exports 重要用于导出 function Parent(){}  这种构造函数,在require中可以直接new 该对象;

exports 主要为导出实例化对象。

es6 import export 与 node 中的module.exports exports的更多相关文章

  1. [转] ES6 import/export:模块导入导出方式

    export导出语法 // default exports export default 42; export default {}; export default []; export defaul ...

  2. 关于es6 import export的学习随笔

    记得之前的一次面试中,有个面试官问了我关于es6导入和导出的一些知识点,可惜当时对这方面没在意,只知道每次机械的import和export,也不知道为啥要这样用,现在静下心来,好好的把这块看了下,顺便 ...

  3. ES6 import export

    import import './module1.js'; (无对象导入) import d from './module1.js'; (导入默认对象) import {Employee, getEm ...

  4. es6 import export 引入导出变量方式

    var testdata='sdfkshdf'; //export testdata;//err export {testdata as ms}; export var firstName = 'Mi ...

  5. node中的require和exports

    http://cnodejs.org/topic/4f16442ccae1f4aa270010e9

  6. 探讨ES6的import export default 和CommonJS的require module.exports

    今天来扒一扒在node和ES6中的module,主要是为了区分node和ES6中的不同意义,避免概念上的混淆,同时也分享一下,自己在这个坑里获得的心得. 在ES6之前 模块的概念是在ES6发布之前就出 ...

  7. require/exports 与 import/export 的区别?

    文章作者:寸志链接:https://www.zhihu.com/question/56820346/answer/150724784来源:知乎 遵循的模块化规范不一样 模块化规范:即为 JavaScr ...

  8. ES6学习笔记(十九)Module 的语法-export和import

    1.概述 历史上,JavaScript 一直没有模块(module)体系,无法将一个大程序拆分成互相依赖的小文件,再用简单的方法拼装起来.其他语言都有这项功能,比如 Ruby 的require.Pyt ...

  9. 关于node中 require 和 ES6中export 、export default的总结

    nodejs中 require 方法的加载规则 方法的加载规则 1. 优先从缓存中加载 2. 核心模块 3. 路径形式的模块 4. 第三方模块 一.优先从缓存中加载 main.js:执行加载a.js模 ...

随机推荐

  1. 【皇甫】☀初识AOP

    新知识,新起点,下面介绍一下aop所要准备架包和各个层 特点: 创建好的各个层: 所需架包: 具体步骤: No.1  搭建分层架构 entity 1 public class User impleme ...

  2. NLog配置文件根节点

    NLog.config 配置文件信息 <nlog xmlns="http://www.nlog-project.org/schemas/NLog.xsd" xmlns:xsi ...

  3. Super Jumping! Jumping! Jumping!

    Nowadays, a kind of chess game called “Super Jumping! Jumping! Jumping!” is very popular in HDU. May ...

  4. getRemoteAddr()和getRemoteHost() 区别

    System.out.println("request.getRemoteAddr(): " + request.getRemoteAddr()); System.out.prin ...

  5. Select For update语句浅析 (转)

    Select … for update语句是我们经常使用手工加锁语句.通常情况下,select语句是不会对数据加锁,妨碍影响其他的DML和DDL操作.同时,在多版本一致读机制的支持下,select语句 ...

  6. jQuery 获取当前节点的html包含当前节点的方法

    在开发过程中,jQuery.html() 是获取当前节点下的html代码,并不包含当前节点本身的代码,然后我们有时候确需要,找遍jQuery api文档也没有任何方法可以拿到. 看到有的人通过pare ...

  7. 增加SWAP空间的方法

    增加swap空间的方法 背景:安装oracle数据库需要,需要设置swap空间为16G,当前swap空间只有4G,需要增加12Gswap空间. 1.创建一个空文件 # dd if=/dev/zero ...

  8. ios异常错误

    1,mach_msg_trap处异常 http://www.jianshu.com/p/2b3f58c61d7d 在lldb下敲入bt (lldb) bt

  9. 记一次 IDEA mybatis.generator 自定义扩展插件

    在使用 idea mybatis.generator 生成的代码,遇到 生成的代码很多重复的地方, 虽然代码是生成的,我们也不应该允许重复的代码出现,因为这些代码后期都要来手动维护. 对于生成时间戳注 ...

  10. 在SpringMVC框架下实现文件的 上传和 下载

    在eclipse中的javaEE环境下:导入必要的架包 web.xml的配置文件: <?xml version="1.0" encoding="UTF-8" ...