File tree Expand file tree Collapse file tree 3 files changed +20
-10
lines changed Expand file tree Collapse file tree 3 files changed +20
-10
lines changed Original file line number Diff line number Diff line change @@ -40,12 +40,20 @@ point.toString() // (2, 3)
4040
4141```
4242
43- 上面代码定义了一个“类”,可以看到里面有一个constructor函数,这就是构造函数。 而this关键字则代表实例对象。
43+ 上面代码定义了一个“类”,可以看到里面有一个constructor函数,这就是构造函数, 而this关键字则代表实例对象。这个类除了构造方法,还定义了一个toString方法。注意,定义方法的时候,前面不需要加上function这个保留字,直接把函数定义放进去了就可以了 。
4444
4545Class之间可以通过extends关键字,实现继承。
4646
4747``` javascript
4848
49+ class ColorPoint extends Point {}
50+
51+ ```
52+
53+ 上面代码定义了一个ColorPoint类,该类通过extends关键字,继承了Point类的所有属性和方法。但是由于没有部署任何代码,所以这两个类完全一样,等于复制了一个Point类。下面,我们在ColorPoint内部加上代码。
54+
55+ ``` javascript
56+
4957class ColorPoint extends Point {
5058
5159 constructor (x , y , color ) {
@@ -61,7 +69,7 @@ class ColorPoint extends Point {
6169
6270```
6371
64- 上面代码定义了一个ColorPoint类,该类通过extends关键字,继承了Point类的所有属性和方法 。在constructor方法内,super就指代父类Point ;在toString方法内,` super() ` 表示对父类求值,由于此处需要字符串,所以会自动调用父类的toString方法 。
72+ 上面代码中,constructor方法和toString方法之中,都出现了super关键字,它指代父类的同名方法 。在constructor方法内,super指代父类的constructor方法 ;在toString方法内,super指代父类的toString方法 。
6573
6674## Module的基本用法
6775
Original file line number Diff line number Diff line change @@ -44,9 +44,9 @@ Node.js的0.11版还不是稳定版本,要使用版本管理工具[nvm](https:
4444
4545``` bash
4646
47- source nvm.sh
48- nvm use 0.11
49- node --harmony
47+ $ source nvm.sh
48+ $ nvm use 0.11
49+ $ node --harmony
5050
5151```
5252
@@ -55,6 +55,7 @@ node --harmony
5555``` bash
5656
5757$ node --v8-options | grep harmony
58+
5859 --harmony_typeof
5960 --harmony_scoping
6061 --harmony_modules
@@ -74,7 +75,7 @@ $ node --v8-options | grep harmony
7475
7576## Traceur编译器
7677
77- Google公司的[ Traceur] ( https://github.com/google/traceur-compiler ) 编译器,可以将ES6代码编译为ES5代码。
78+ Google公司的[ Traceur] ( https://github.com/google/traceur-compiler ) 编译器,可以将ES6代码编译为ES5代码。这意味着,你可以用ES6的方式编写程序,又不用担心浏览器是否支持。
7879
7980它有多种使用方式。
8081
@@ -173,7 +174,7 @@ $traceurRuntime.ModuleStore.getAnonymousModule(function() {
173174
174175``` bash
175176
176- npm install -g traceur
177+ $ npm install -g traceur
177178
178179```
179180
@@ -189,11 +190,11 @@ Calc constructor
189190
190191```
191192
192- 如果要将ES6脚本转为ES5 ,要采用下面的写法
193+ 如果要将ES6脚本转为ES5保存 ,要采用下面的写法
193194
194195``` bash
195196
196- traceur --script calc.es6.js --out calc.es5.js
197+ $ traceur --script calc.es6.js --out calc.es5.js
197198
198199```
199200
@@ -203,7 +204,7 @@ traceur --script calc.es6.js --out calc.es5.js
203204
204205``` bash
205206
206- traceur --script calc.es6.js --out calc.es5.js --experimental
207+ $ traceur --script calc.es6.js --out calc.es5.js --experimental
207208
208209```
209210
Original file line number Diff line number Diff line change 3030- Dmitry Soshnikov, [ ES6 Notes: Default values of parameters] ( http://dmitrysoshnikov.com/ecmascript/es6-notes-default-values-of-parameters/ ) : 介绍参数的默认值
3131- Mozilla Developer Network, [ WeakSet] ( https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/WeakSet ) :介绍WeakSet数据结构
3232- Mathias Bynens, [ Unicode-aware regular expressions in ES6] ( https://mathiasbynens.be/notes/es6-unicode-regex ) : 详细介绍正则表达式的u修饰符
33+ - Jack Franklin, [ An introduction to ES6 classes] ( http://javascriptplayground.com/blog/2014/07/introduction-to-es6-classes-tutorial/ ) : ES6 class的入门介绍
3334
3435## Generator
3536
You can’t perform that action at this time.
0 commit comments