【发布时间】:2016-10-12 18:23:40
【问题描述】:
我正在尝试学习 ES2015 JavaScript 类,我开始编写这样的代码:
文件:index.js
/* parent class */
class Thing {
construct(){
console.log("thing constructor");
}
}
/* child class */
const Human = class Human extends Thing {
construct(){
super();
}
}
let Person = new Human();
文件:package.json
{
"scripts": {
"serve": "nodemon index.js --exec babel-node"
},
"dependencies": {
"babel-cli": "^6.9.0",
"babel-preset-es2015": "^6.9.0"
}
}
通过运行:
$ npm run serve
但我明白了:
SyntaxError: index.js: super() outside of class constructor (14:3)
12 |
13 | construct(){
> 14 | super();
| ^
15 | }
我在这里错过了什么?
节点版本:6.2.1
【问题讨论】:
标签: javascript node.js class ecmascript-6