Search Results

Search found 1 results on 1 pages for 'user227353'.

Page 1/1 | 1 

  • how does memory stacks work in javascript

    - by user227353
    When we have code like: function a(){ var x =0; this.add=function(){ alert(x++); } } var test = new a(); test.add(); // alert 0 test.add(); // alert 1 test.add(); // alert 2 How does this work? Doesn't that the value of 'x' in a() should be 'gone' as soon as test = new a() is complete? The stack contains x should also be gone as well, right? Or, does javascript always keep all the stacks ever created in case they will be referenced in future? But that wouldn't be nice, would it...?

    Read the article

1