有什么方法可以捕获整个函数闭包,然后在其他代码位置引用它? 我想做这样的事情:
var captured_closure;
function anything() {
var x = 10;
var y = "k";
captured_closure = current_function_closure;
}
anything();
console.log(captured_closure.x); //Should be 10
console.log(captured_closure.y); //Should be k
可能的目标是导出由特定函数处理的所有变量(我可以将其逐个导出,但是将它们全部拥有会更方便),然后在开发人员工具中对其进行操作以进行调试。 谢谢。
[edit]抱歉,我以前错过了函数内的vars。现在已更正。