I'm trying to re-use variable inside a function that calls a callback, but it does not work the way I think it should;
another()(); //=> logs "somevalue"
callingfn(); //=> logs " someval is not defined"
function a(fn){
var someval = "some-value";
return fn();
}
function callingfn(){
return a.call(this, function(){
console.log(someval)
})
}
function another(){
var sv = "somevalue";
return function(){
console.log(sv);
}
}
I'm not able to understand if this is closure-related problem, but at first I expected that someval in callingfn would have been defined.
Where am I wrong?
somevalis local to the functiona()and will be accessible only insidea()and any closures insidea()(there are none in the code you posted).a()a()