Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

193
Vistas
JavaScript - Get variable original name by it's prototype

How can i get the original name of the variable by it's prototype? I tried MyVar.name but it's not defined.

I have a function for example which get the original variable name.

function varName(v) {
  return v.toString();
}

But when I call it with variable object, it returns [Object object].

varName(window);

I want to make it return the original variable name.

varName(window);
// window
about 4 years ago · Juan Pablo Isaza
2 Respuestas
Responde la pregunta

0

As @traktor said, it cannot be done, but there is an available workaround for you:

Create a function, so that you can name your variable:

foo = function(name) {
   this.name = name;
}

And, while creating one, call it:

var pear = new foo("pear");
about 4 years ago · Juan Pablo Isaza Denunciar

0

;TLDR

The short but negative answer is it can't be done. Prototyping potentially applies to values stored in a variable, not to names used in code to refer to the variable. If you still have an insurmountable problem please edit the question to provide more details about the actual coding or design issue that remains.

Variable names

A variable name is an identifier used to access the location where the value of the variable is stored. There is no inverse relationship: the value of a variable contains no information about where it is stored.

Because JavaScript supports run time evaluation using variable names in expressions, the compiler and run time engine maintain "bindings" of variable names with the location where they are stored in memory. Such bindings are stored in global and function environment records. The structure and contents of the environment records are, however, not accessible from within JavaScript. You can no more determine the name of variable a function argument might have been stored in prior to being passed to a function by value that you could determine where in a scope chain of environment records a variable being read in code was defined.

about 4 years ago · Juan Pablo Isaza Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda