Use class from a different file

Asked 1 years ago, Updated 1 years ago, 61 views

I can now use calss from es6, but please tell me how to use it after writing a class in another file like c#.
(Environment is running on command prompt with node.js)

Multipost

javascript node.js es6

2022-09-30 21:27

2 Answers

Please refer to the link in the comment below and it worked.
Class Editor File

module.exports=class Cat{
// the middle of a class
}

User side files

const Cat=require(./filename);
let cat = new Cat;


2022-09-30 21:27

For ES6, the class definition is as follows:

export default class Cat{
}

I think this is fine for the user.

import Cat from 'Cat';

When you do the above, you will need to transfer it to the babel.I added m(__)m


2022-09-30 21:27

If you have any answers or tips


© 2024 OneMinuteCode. All rights reserved.