admin管理员组文章数量:1406741
How to alert variable name, not a value of variable?
var color = 'red';
alert(color); // Will alert 'red'
alert(/* magic */); // Will alert 'color'
How to alert variable name, not a value of variable?
var color = 'red';
alert(color); // Will alert 'red'
alert(/* magic */); // Will alert 'color'
Share
Improve this question
asked Apr 17, 2010 at 19:41
Randy GurmentRandy Gurment
1772 silver badges6 bronze badges
1
-
9
alert("color");
? – kennytm Commented Apr 17, 2010 at 19:42
2 Answers
Reset to default 5It's not possible in JavaScript, because arguments in this language are passed by value or by reference, not by name, so when variable is passed to function, its name is lost.
In the Firebug console:
>>> a=[]
[]
>>> a
[]
>>> b=a
[]
>>> a.push(3)
1
>>> b
[3]
>>> a
[3]
So, which variable name would you like that array to return? a
? b
? Something pletely different?
本文标签: javascriptHow to alert variable namenot a valueStack Overflow
版权声明:本文标题:javascript - How to alert variable name, not a value - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1744843067a2628042.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论