Imagine I have this class:
class Class {
constructor(arg1, arg2) { arg1 = arg2};
}
Should I do this?
class Class = exports.Class {
constructor(arg1, arg2) { arg1 = arg2};
}
Or there's another way?
Imagine I have this class:
class Class {
constructor(arg1, arg2) { arg1 = arg2};
}
Should I do this?
class Class = exports.Class {
constructor(arg1, arg2) { arg1 = arg2};
}
Or there's another way?
With export syntax, just put export before the class:
export class Class {
(this results in a named export named Class)
Or, for a default export:
export default class Class {
With module syntax, assign to module.exports, or to a property of module.exports:
module.exports = class Class {
or
module.exports.Class = class Class {
You should do like this (for other ways, check @Snow answer):
class Class {
constructor(arg1, arg2) { arg1 = arg2};
}
module.exports = Class;