I'm wondering how I can bind variables to a closure function. Let me use this code:
Please see the code here:
function makeCall(callback) {
var fs = callback.toString();
var stored_callback = eval('(' + fs + ')').bind({ });
stored_callback();
}
function foo(id) {
makeCall(function() {
console.log(id);
});
}
foo('bar');
After the call of eval, the called function cannot reach the id as it should as a closure.
My question is that before calling the toString, can I somehow retrieve the 'context' of a closure to be stored and retrieved and bind to the call?