From 2755c1809db6fb6675a54e7668794357b40a1245 Mon Sep 17 00:00:00 2001 From: ruanyf Date: Sat, 11 Jun 2016 20:38:39 +0800 Subject: [PATCH] =?UTF-8?q?docs(module):=20=E5=A2=9E=E5=8A=A0=E6=B5=8F?= =?UTF-8?q?=E8=A7=88=E5=99=A8=E7=9A=84=E6=A8=A1=E5=9D=97=E4=BD=BF=E7=94=A8?= =?UTF-8?q?=E6=96=B9=E6=B3=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- docs/module.md | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/docs/module.md b/docs/module.md index 3b44a96..b61ad77 100644 --- a/docs/module.md +++ b/docs/module.md @@ -36,6 +36,16 @@ import { stat, exists, readFile } from 'fs'; - 将来浏览器的新API就能用模块格式提供,不再必要做成全局变量或者`navigator`对象的属性。 - 不再需要对象作为命名空间(比如`Math`对象),未来这些功能可以通过模块提供。 +浏览器使用ES6模块的语法如下。 + +```html + +``` + +上面代码在网页中插入一个模块`foo.js`,由于`type`属性设为`module`,所以浏览器知道这是一个ES6模块。 + +Node的默认模块格式是CommonJS,目前还没决定怎么支持ES6模块。所以,只能通过Babel这样的转码器,在Node里面使用ES6模块。 + ## 严格模式 ES6的模块自动采用严格模式,不管你有没有在模块头部加上`"use strict";`。