Categories
JavaScript Answers

How to fix the Expected ‘this’ to be used by class method error with JavaScript?

Spread the love

Sometimes, we want to fix the Expected ‘this’ to be used by class method error with JavaScript.

In this article, we’ll look at how to fix the Expected ‘this’ to be used by class method error with JavaScript.

How to fix the Expected ‘this’ to be used by class method error with JavaScript?

To fix the Expected ‘this’ to be used by class method error with JavaScript, we should change the function causing the error to an arrow function.

For instance, we write

const getUrlParams = (queryString) => {
  //...
};

to define the getUrlParams as an arrow function.

Then if it doesn’t reference this, then the error would go away.

Conclusion

To fix the Expected ‘this’ to be used by class method error with JavaScript, we should change the function causing the error to an arrow function.

Leave a Reply

Your email address will not be published.

If you like the content of this blog, subscribe to my email list to get exclusive articles not available to anyone else.