获取变量的name属性 [英] Get the name property of a variable

查看:84
本文介绍了获取变量的name属性的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想知道是否可以在javascript或JQuery中获取变量的名称。

I was wondering if it's possible to get the name of a variables in javascript or JQuery.

假设我在javascript中声明一个变量,如:

Suppose that I declare a variable in javascript like:

var customerNr = "456910";

如果函数接收变量,我该如何返回变量的名称?

If a function receive a variable, how can i return the name of the variable?

例如:

function getNameOfVariable(someVariable){
     //return name of someVariable;
}

如果我这样调用这个函数:

If I call this function like this:

getNameOfVariable(customerNr);

该函数必须返回一个值为customerNr的字符串。

The function has to return a string whose value is "customerNr".

如何在jquery或javascript中执行此操作?某种反思?

How can I do this in jquery or javascript? Some kind of reflection?

推荐答案

这根本不可能!

传递的参数甚至不必具有名称。它可以是函数或原始文字的返回值(如string 3 )。

The passed parameter doesn't even have to have a name. It could be a return value of a function or a raw literal (like "string" or 3).

这篇关于获取变量的name属性的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆