Need help with Event's

File 1:

class Client {
    constructor() {
       this.login = (token) => {
         this.emit("ready", this)
       }
    }
}

module.exports.Client = Client;

file 2:

let xx = require("file_dir")
let client = new xx.Client();
client.on("ready", () => console.log("ready"))
client.login("blah")

I get 2 errors, client.on is not a functionandthis.emit is not a function`

I am no expert on this, but I have found an article that may help. https://codeburst.io/event-emitters-and-listeners-in-javascript-9cf0c639fd63?gi=f16ff907b6d2

1 Like

I was looking for an article that was actually good, that explained it properly and couldn’t, the article you linked help me! Thank you!

1 Like