Search Results

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

Page 1/1 | 1 

  • how could I pass closure problems in order to increment a global var

    - by hyptos
    I have a simple goal, I would like to increment a variable but I'm facing the closure problem. I've read why this s happening here How do JavaScript closures work? But I can't find the solution to my problem :/ let's assume this part of code I took from the link. function say667() { // Local variable that ends up within closure var num = 666; var sayAlert = function() { alert(num); //incrementation } num++; return sayAlert; } I would like to increment num within the function and to keep the changes to num. How could I do that ? Here is the JsFiddle where I have my problem, I can't figure out how to increment my totalSize and keep it. http://jsfiddle.net/knLbv/2/ I don't want a local variable that ends up with closure.

    Read the article

1