I have below probably a bunch of problems but let’s simplify them with easier examples.
Let assume two vars, a=cat and b=a, and you want to reference by bs value a to that var ie a. So by which command I can do it? Variable SomeCommand(b) and variable a should point to the same memory space becaues b gets evaluated to a. The same question arises from the below code where we have the part document.getElementById(vals[0].split('|')[0]).style.display= 'block'; that should be evaluated to document.getElementById(picture).style.display= 'block'; ie to show picture but the above example is much cleaner to explain so refer to it, please. How to do the reference? Are the two ways above equivalent? I am watchful here because having encountered similar problems in other languages but then they were about inodes, symbolic/hard links and such things but no idea how this works in JS. Shortly, how do they get evaluated?
function change_visibility(binX)
{
// binX is a thing that matches `/^[10Xx]+$/`
// 1 = show the thing
// 0 = do not show the thing
// x/X = do not do anything
//
// for example, 00011x would turn OFF picture-quote-question_mark
// while turning ON search and help but not doing anything to
// typing pad's current state
var vals = ['picture|binX.charAt(0)',
'quote|binX.charAt(1)',
'question_mark|binX.charAt(2)',
'search|binX.charAt(3)',
'help|binX.charAt(4)',
'typingPad|binX.charAt(5)'
];
for (var i=0; i<vals.length; i++)
{
if(vals[i].split('|')[1]==1)
{
//TODO: check whether you can do it like this,
// assumed for example that vals[0].split('|')[0] =picture
// but it is not, the "inode" or let call it arrow is diffent!
// ERROR HERE ?!?
document.getElementById(vals[i].split('|')[0]).style.display= 'block';
}
else if(vals[i].split('|')[1]==0)
{
document.getElementById(vals[i].split('|')[0]).style.display= 'none';
}
}
}
Please, fix the labels if you know more descriptive alternatives.
You might want to revise your question. I’m not entirely sure what you’re asking. Is there a problem with this code you can’t figure out? What is it suppose to do? The whole a, b reference portion of the conversation has nothing to do with the code you submitted. The variable you’re passing isn’t used in your code. Also your if statement compares the split to == 1. But, it will never be equal to 1 or 0. It will only be one of those phrases to the right of ‘|’. Anyway maybe you can revise your question and it will make more sense.
Let me rewrite your code a little so you don’t have that binX junk in the array.
That might have been what you were after. So if binX is ‘10000’ then ‘picture’ would be shown, and the rest would be hidden. Maybe that’s what you were after. This solution is better because you aren’t using eval() which you should avoid if you don’t have to, and this code you don’t have to.