javascript - Increment the name of variable -


basically want increment name of variable. correct syntax this?

for (i=0; i<5; i++) {     eval("var slider_" + i);      var slider_+i = function(){     //some code }  dojo.addonload(slider_+i); 

why not use array?

var slider = [];  (i=0; i<5; i++) {     slider[i] = function(){         //some code     }      dojo.addonload(slider[i]); } 

alternatively, access them based on object contained within. assuming global variables (hopefully not):

for (i=0; i<5; i++) {     window["slider_"+i] = function(){         //some code     }      dojo.addonload(window["slider_"+i]); } 

window["something"] way access global variable named something.


Comments

Popular posts from this blog

objective c - Change font of selected text in UITextView -

php - Accessing POST data in Facebook cavas app -

c# - Getting control value when switching a view as part of a multiview -