Next.js Discord

Discord Forum

Using fellow methods within same Class in NextJs

Silver Fox posted this in #help-forum
Open in Discord
Silver FoxOP
Hello 🙏

In Javascript . How do u call a method from another method within the same class?
I googled and saw that I could use the 'this' keyword, but when I log the 'this' keyword... It's undefined.
I don't know whether this has something to do with me using Nextjs

Let's say I have something like this
class Text {
sayHi() {
shout() {

I tested this within my browser js console and it works
I did it same way in nextJs and it doesn't seem to work

3 Replies

Satin Angora
What do you mean with "in nextjs"?
In pages/components you just call the function, your component or page shouldnt be a class. Need more context in what your trying to accomplish in next.
What’s your use case? You shouldn’t be using classes inside components…
Silver FoxOP
Ah damn I'm sorry I failed to mention that.
It's a service class I use to interact with the database.
It's defined in a lib folder in the src dir.

It just provides helper methods to interact with my db

Once again, I apologize for not including that info 🙏🙏