2

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?

4

1 回答 1

1

根据 Felix King 的回答,这是不可能的。:( 太糟糕了。我只是想存储调用并在以后执行某种持久性级别。这样即使计算机重新启动或任何事情都可以进行交互......似乎唯一的方法是不使用嵌入器参数从'关闭',是吧?无论如何非常感谢!

于 2013-06-03T05:22:49.790 回答