To fix "Uncaught TypeError: Illegal invocation" in Chrome and JavaScript, we should make sure we’re calling a function.
For instance, we write
const obj = {
someProperty: true,
someMethod() {
console.log(this.someProperty);
},
};
obj.someMethod();
to define the obj
with the someMethod
method.
Then we call it with obj.someMethod();
.
It logs true
since this
is the obj
object.