This is a contrived example but I'm just trying to understand how scoping works.
Can someone explain why the following throws an error? I'm not sure why adding this.otherThing = otherThing
would be necessary if callback is executed in the context of where otherThing
is defined.
function doSomething(callback){
// works if the following is added
// this.otherThing = otherThing
function otherThing(val){
return val
}
callback()
}
let callback = someVal => {
console.log('was given:',otherThing(someVal))
}
doSomething(() => callback('some value'))