closures - is it possible to make the "value" self-increase in setTimeout() method in Javascript? -


Is it possible to self-increase "value" in the setTimeout () method in Javascript?

My code looks like a code block below I have two for loops in the init () method, and in the internal loop I apply "1 myfun = function testfunc (year, value)" every 1 second Function to "

but I still have a feature called" value "which

1. I want" value "to be extended every time, < / P>

2. Or make changes to "value", then the next time this function has been applied "var myfun = function testFunc (year, value)" then Or "value";

But now I get in the function "my myfun = function testFunc (year, value)" I can get the year [data] properly, but " Value "is always the same.

Did the" value "or every time change? Really appreciate any help or answer.

  ... init (); Function for init () {... var (= var state in dataset) {var i = 0; Var for value = 18; (different year in the dataset [state]) {i ++; setTimeout ("myfun ("+ Year +", "+ value +") ", i * 1000);}}} var myfun = function testFunc (year, value) I want to increase "value" all the time, make changes to // or "value", then use the new "value" next time to invite this event; Price ++; Console.log ("year:" + year + ", value:" + value); }    

I think this is possible when you type setTimeout Function with callback (which you should do anyway, because string notation is not recommended):

  function init () {// ... for var state in dataset) {var i = 0; Var values ​​= 18; (Different year in the dataset [state]) {i ++; SetTimeout (function () {myfun (year, ++ value);}, i * 1000); }}} Var myfun = function testFunc (year, value) {console.log ("year:" + year + ", value:" + value); }    

Comments

Popular posts from this blog

php - PDO bindParam() fatal error -

logging - How can I log both the Request.InputStream and Response.OutputStream traffic in my ASP.NET MVC3 Application for specific Actions? -

java - Why my included JSP file won't get processed correctly? -