mirror of
https://github.com/ruanyf/es6tutorial.git
synced 2025-05-27 20:32:21 +00:00
修改class/extends
This commit is contained in:
parent
0d3a7ea26a
commit
4c9b971e57
@ -142,6 +142,23 @@ p1.printName() // Ha
|
||||
|
||||
上面代码在ColorPoint的实例p2上向Point类添加方法,结果影响到了Point的实例p1。
|
||||
|
||||
下面是一个继承原生的Array构造函数的例子。
|
||||
|
||||
```javascript
|
||||
|
||||
class MyArray extends Array {
|
||||
constructor(...args) {
|
||||
super(...args);
|
||||
}
|
||||
}
|
||||
|
||||
var arr = new MyArray();
|
||||
arr[1] = 12;
|
||||
|
||||
```
|
||||
|
||||
上面代码定义了一个MyArray的类,继承了Array构造函数。因此,就可以从MyArray生成数组的实例。
|
||||
|
||||
有一个地方需要注意,类和模块的内部,默认就是严格模式,所以不需要使用`use strict`指定运行模式。考虑到未来所有的代码,其实都是运行在模块之中,所以ES6实际上把整个语言升级到了严格模式。
|
||||
|
||||
## Module的基本用法
|
||||
|
@ -16,7 +16,7 @@
|
||||
- Nicholas C. Zakas, [Understanding ECMAScript 6](https://github.com/nzakas/understandinges6)
|
||||
- Justin Drake, [ECMAScript 6 in Node.JS](https://github.com/JustinDrake/node-es6-examples)
|
||||
- Ryan Dao, [Summary of ECMAScript 6 major features](http://ryandao.net/portal/content/summary-ecmascript-6-major-features)
|
||||
- Luke Hoban, [ES6 features](https://github.com/lukehoban/es6features)
|
||||
- Luke Hoban, [ES6 features](https://github.com/lukehoban/es6features): ES6新语法点的罗列
|
||||
- Traceur-compiler, [Language Features](https://github.com/google/traceur-compiler/wiki/LanguageFeatures): Traceur文档列出的一些ES6例子
|
||||
- Axel Rauschmayer, [ECMAScript 6: what’s next for JavaScript?](https://speakerdeck.com/rauschma/ecmascript-6-whats-next-for-javascript-august-2014): 关于ES6新增语法的综合介绍,有很多例子
|
||||
- Toby Ho, [ES6 in io.js](http://davidwalsh.name/es6-io)
|
||||
|
Loading…
x
Reference in New Issue
Block a user