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.