Closing Javascript in firebug

so ... I'm trying to learn this new thing called closure ... new for me ... Out of academic interest:

DESCRIPTION

When I create a global variable or function in JS - I can easily see them on the Firebug DOM tab (they are attached to the Window object). When I create objects - the same story. I see objects on the Firebug DOM tab.

Question:

What about variables and functions inside closures - what are they attached to? I do not see these private variables in the Firebug DOM tab. So should it work?

(function () {
    var test1 = 'test'; //do't se it in DOM
    function test2(){  //do't see it in DOM
    }
}());
+3
source share
2 answers

DOM , . .

, , , , , . , DOM.

:

  var increment = (function(){
    var i = 0;
    return function() { 
      return i++;
    }
  })();

  increment(); // should return 0
  increment(); // should return 1

i, , return i++; i " " Script.

+2

, . Firebug ( 1.11.2) . .

closure.%variable

DOM, , DOM .

0

Source: https://habr.com/ru/post/1780370/


All Articles