When we have an object and a method inside it, this refers to the object that it belongs to:
let myObj = {
data: 'someData',
test() {
console.log(this);
},
};
myObj.test();
here the result is : myObj
but what if my method is in a class with constructor?
export default class MovieCard extends React.Component {
constructor(props) {
super(props);
this.state = { content: 'test' };
}
changer() {
console.log(this);
}
render() {
return null;
}
}
It seems, in this case, this equals to 'undefined' why is that? is it because it has not been called yet?