Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

【ES6/Module】模块 #5

Open
Kelichao opened this issue Jan 18, 2017 · 0 comments
Open

【ES6/Module】模块 #5

Kelichao opened this issue Jan 18, 2017 · 0 comments

Comments

@Kelichao
Copy link
Owner

Kelichao commented Jan 18, 2017

export命令(用于导出)

export命令由于是es6语法,所以在node环境中需要用babel进行转码

// profile.js
// 必须放在全局作用域,不然报错
var  name = "Bob";
var age = 23;
export {name, age};

import命令(用于接收)

import命令由于是es6语法,所以在node环境中需要用babel进行转码

  • 别把commonJS规范(require)与es6的语法(import)支持混淆
// main.js
import {name, age} from"./profile";
// import “./profile”   转码之后即为   require("./profile");

Module

  • module命令可以取代import达到整体输入模块的目的
// main.js
module circle from "./circle";

module.extprts与exports.的区别

// exports只是module.exports的一个辅助方法
// 推荐方式
exports.add = add;

// module.exports是真是存在的东西
// 不推荐
module.exports = add;
@Kelichao Kelichao changed the title 【ES6/Module】 【ES6/Module】模块 May 2, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant