With ECMAScript 2015, you can export and import several classes like this
class Person { constructor() { this.type = "Person"; } } class Animal{ constructor() { this.type = "Animal"; } } module.exports = { Person, Animal };
then where do you use them:
const { Animal, Person } = require("classes"); const animal = new Animal(); const person = new Person();
In case of name conflicts or you prefer other names, you can rename them as follows:
const { Animal : OtherAnimal, Person : OtherPerson} = require("./classes"); const animal = new OtherAnimal(); const person = new OtherPerson();
Jonas Brandel Mar 02 '18 at 20:45 2018-03-02 20:45
source share