How to automatically modify variable names in ruby and javascript? -
How to automatically modify variable names in ruby and javascript? -
i want like:
for(var i=0; < 3, i++) { var file_i = i; }
and got local variables: file_0 = 0,file_1 = 1, file_2 =2
i'm want know how create happen in ruby.
if don't mind new variables beingness global:
for(var i=0; < 3, i++) { window["file_" + i] = i; }
but comments have noted, bad idea. create these properties of object:
var files = { }; for(var i=0; < 3; i++) { // <-------- typo there. should ; after < 3 files["file_" + i] = i; }
and can read these properties with:
for (var key in files) { if ({}.hasownproperty.call(files, key)) alert(key + " " + files[key]); }
i'm afraid don't know how ruby.
javascript ruby
Comments
Post a Comment