0
我试图将if语句置于一个函数内,并且条件基于函数中使用的参数的名称,而不是值。在JavaScript中检查参数名称,而不是值
什么条件可以用来实现这一目标?可能吗?如果没有,是否有替代方案?
例如:
var lorem="The name is Lorem, but the value isn't.";
var ipsum="The name is Ipsum, but the value isn't.";
//the values shouldn't matter
logIt(Lorem);
function LogIt(theName){
if(**the name of the variable theName = "lorem"**){
console.log("The variable 'lorem' was used.");
}else if(**the name of the variable theName = "ipsome"**){
console.log("The variable 'ipsum' was used.");
}else{
console.log("huh?");
}
}
另外,你选择将是永远不要依赖传递的变量的名称(谁是说那里甚至有一个?)。这是非常不合逻辑的代码。 –
你想解决什么具体问题? –
我通过简单地跟踪迭代来解决它。谢谢! – kennsorr