【发布时间】:2015-06-15 05:08:22
【问题描述】:
我知道这完全没用,但我还是很好奇。是否可以执行以下操作?
function getVariableName ( v )
{
// .... do something .....
// return the string "v"
}
var x = 69;
var y = "somestring";
console.log(getVariableName(x)); // prints "x" to the console
console.log(getVariableName(y)); // prints "y" to the console
【问题讨论】:
-
不,但您可以使用
arguments字符串 -
为什么需要这个名字?
-
不,你不能那样做。调用环境中提到
x,导致x的value被传递,一个值就是一个值;它与变量没有内在关系。 -
为什么需要打印变量名?
-
我不禁想知道,你为什么要这样做?
标签: javascript