1つのファイルで定義されたクラスを使用し、別のファイルをnode.jsで拡張する正しい方法は何ですか?ES6クラス、異なるファイルに親があり、node.js?
現在、私が持っている:私が持っている '子' クラスファイルで
'use strict'
class BasePageHandler {
constructor(app, settings, context) {
}
}
return module.exports;
:I場合、
TypeError: Class extends value #<Object> is not a function or null
注:
'use strict'
var BasePageHandler = require ('./../BasePageHandler.js');
class FrontpagePageHandler extends BasePageHandler {
constructor(app, settings, context) {
super(app, settings, context);
this.settings = settings;
this.context = context;
}
}
これは、次のエラーで失敗します同じファイルにBasePageHandlerを持っていればうまくいきますので、クラスが別のファイルにあるときに問題があります。
現在ノード4.4.0を使用しています。あなたは正しくBasePageHandler.js
ファイルにクラスをエクスポートする必要が
](https://www.npmjs.com/package/babel-plugin-transform-es2015-modules-commonjs)の代わりに 'module.exports'を使います。そうすれば、Nodeがネイティブにモジュールを実装しているときに、あなたのコードは未来の状態のままになります。 –