I’m still trying to understand javascript scoping. What is the simplest way to return a value from an anonymous callback function? For instance,
var test = 'outside';
callsFunction(function() { test = 'inside'; });
console.log(test);
where callsFunction calls the anonymous function. I would like this to print ‘inside’.
I’m a little bit confused, but I believe this is what you’re after
Note that any function can be invoked via the usage of
(). However, there are special methods for invoking functions from different contexts, such as Function.call() and Function.apply()