I am using several fat arrow functions in a javascript class but my this keeps having a null value. This is for a reactjs application using sagas. From prior readings, etc. I was under the assumption that fat arrow functions got their scope from the parent they were contained in. However, that is not what is happening here.
Here is an example illustrating the issue I am having:
export default class Base {
constructor() {
this.autos = [];
}
}
export default class Auto extends Base {
createAuto = (auto) => {
debugger;
this.autos.push(auto); /This line is where this = null
return this.autos;
}
}
……
function* createAuto(auto) {
try {
let a = new Auto();
…..
let result = yield(a.createAuto, auto);
} catch (e) {
console.log(e);
}
}
When createAuto method is called, this is null. How could this be the case if createAuto is contained within the Auto class? I would think this would be the one for Auto.