【发布时间】:2010-12-20 04:13:51
【问题描述】:
下面可能有很多问题,但让我们用更简单的例子来简化它们。
假设有两个变量a=cat 和b=a,并且您希望通过bs 值a 引用该变量,即a。那么我可以通过哪个命令来做到这一点?变量SomeCommand(b) 和变量a 应该指向相同的内存空间,因为b 被评估为a。同样的问题出现在下面的代码中,我们有部分document.getElementById(vals[0].split('|')[0]).style.display= 'block'; 应该被评估为document.getElementById(picture).style.display= 'block'; 即显示图片,但上面的例子解释得更清楚,所以请参考它。怎么做参考?以上两种方式是否等价?我在这里保持警惕,因为在其他语言中遇到过类似的问题,但后来它们是关于索引节点、符号/硬链接等的,但不知道这在 JS 中是如何工作的。很快,他们如何得到评估?
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';
}
}
}
如果您知道更多描述性替代方案,请修正标签。
【问题讨论】:
标签: javascript variables reference evaluation