This is not related to this
as such func.apply
and func.call
do not apply (no pun intended).
I need to pass the current context of a function to another function, by which I mean I need access to the named local variables within a function.
here is a somewhat contrived example:
function doSomething(f){
eval(f)
}
function test(callback){
doSomething("callback.apply(1, 2)")
}
test(function(a, b){
console.log(a + b);
})
How can I pass the local variable callback
to doSomething
so it is available to eval
- I recognise this is a contrived example. Is this even possible?
I know that nested contexts carry over, so if I were to declare doSomething
within test
this would just work. However that does not help me.