Javascript 捕获当前函数关闭

Javascript 捕获当前函数关闭,javascript,Javascript,有没有办法捕获整个函数闭包,然后在代码的其他地方引用它? 我想这样做: 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_clos

有没有办法捕获整个函数闭包,然后在代码的其他地方引用它? 我想这样做:

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
May的目标是导出由特定函数处理的所有变量(我可以一个接一个地处理,但拥有它们会更方便),然后在开发人员工具中操作它们以进行调试。 多谢各位

[编辑]抱歉,我之前错过了函数中的变量。现在已更正。

可能与