在Node.js 4.2.1上运行以下代码时:
'use strict';
var util = require('util');
class MyClass {
constructor(name) {
this.name = name;
}
}
function MyDerived() {
MyClass.call(this, 'MyDerived');
}
util.inherits(MyDerived, MyClass);
var d = new MyDerived();Run Code Online (Sandbox Code Playgroud)
我收到以下错误:
constructor(name) {
^
TypeError: Class constructors cannot be invoked without 'new'
Run Code Online (Sandbox Code Playgroud)
我想知道是否可以从ECMAScript 6类继承旧式JavaScript"类"?并且,如果可能的话,那怎么样?