What is the right way to use a class defined in one file and extend it another, in node.js?
Currently I have:
'use strict'
class BasePageHandler {
constructor(app, settings, context) {
}
}
return module.exports;
In the 'child' class file I have:
'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;
}
}
This fails with the following error:
TypeError: Class extends value #<Object> is not a function or null
Note, if I have the BasePageHandler in the same file then it works, so it is really when the class is in another file I have an issue.
Currently using node 4.4.0.
module.exports. That way, your code will stay future-ready for when Node implements modules natively.