Javascript pass variable by reference -


How can I pass the variable with reference to the call back function of the set interval?
I do not want to define a global variable, is it just possible for the counter?

  var intervalID; Function Test () {var value = 50; IntervalID = setInterval (function () {inc (value);}, 1000); } Function ink (value) {if (value> 100) clearInterval (intervalID); Value = value + 10; }      testing();  

If you turn one off for it, you value it at all, this interior Will be available in the scope, but not outside the test function:

  function test () {var value = 50; Var intervalID = setInterval (function () {// We can still use 'value' and 'intervalID', although they are not valid if (value> 100) clear interval (intervalid); value + = 10 ;}, 1000); }  testing();  

Comments

Popular posts from this blog

sql - dynamically varied number of conditions in the 'where' statement using LINQ -

asp.net mvc - Dynamically Generated Ajax.BeginForm -

Debug on symbian -