2

Is there any way to capture the whole function closure and then refer to it in other places of code? I want to do something like that:

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 goal is to export all variables processed by a particular function (I may do it one-by-one but it would be more convenient to have them all) and then to manipulate them in developer tools for debugging purposes. Thank you.

[edit] Sorry, I missed vars inside the function previously. It's corrected now.

Liberat0r
  • 1,744
  • 2
  • 15
  • 21
  • Possible duplicate of [Get list of closure variables in Javascript](https://stackoverflow.com/questions/35223591/get-list-of-closure-variables-in-javascript) – Oleksandr Martyniuk Aug 29 '18 at 13:19

0 Answers0