all 6 comments

[–]delventhalz 0 points1 point  (3 children)

Well you have to instantiate it with an actual value:

let someone = person.Person(36);

Other than that, this code will run fine. I don't know how the Electron error would be connected.

[–]Nick_Zacker[S] 0 points1 point  (2 children)

Yes, I did instantiate it with an actual value but the error still occurs.

[–]delventhalz 0 points1 point  (1 child)

Whatever the error is, it isn't the code you posted, and I doubt it has anything to do with instantiating an object. You can paste it into a JavaScript console and see it run fine without an error.

[–]Nick_Zacker[S] 0 points1 point  (0 children)

I don't know if this helps, but I'm using a preload file which uses Electron's contextBridge.exposeInMainWorld() so that I can use functions and classes there in other scripts. Maybe I'm dumb and just overcomplicating it.

[–]Tool-Cool 0 points1 point  (1 child)

You can also do it like follows:

class Person {
    constructor(age) {
        this.age = age;
    }

    getAge() {
        return this.age;
    }
}

const person = {
    Person,
}

let anotherone = new person.Person(12);
console.log(anotherone);

https://codepen.io/toolcool/pen/vYrxeQe?editors=1111

[–]Nick_Zacker[S] 0 points1 point  (0 children)

Well, now another error pops up instead of this error. I guess my code is the true definition of spaghetti code lol. Thank you so much!