I want to convert require( "./handlers/event.js")(client)
to es6 but can't find how to do it.
Asked
Active
Viewed 30 times
2

magmalife
- 23
- 4
-
Does this answer your question? [The difference between "require(x)" and "import x"](https://stackoverflow.com/questions/46677752/the-difference-between-requirex-and-import-x) – Ahmed Shaqanbi Dec 17 '21 at 17:46
1 Answers
0
That line is importing from a module that looks like this
module.exports = function(client) {
this.newClient = function() {
var x = client()
// ...
}
}
Which in ES6 would look like this
export default function(client) {
this.newClient = function() {
var x = client()
// ...
}
return this
}
For importing that in an ES6 way, should be something like
import FOO from "./handlers/event"
And then you can do something like
const { newClient } = FOO(new Client())
const p = newClient() // or anything you want to do with it

Wolfgang
- 1,328
- 2
- 8
- 11