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

168
Vistas
member function is not able to access its member properties?

I am a newbie to javascript learning objects. I created an object here is the code

const address = {
    street: "",
    city: "",
    zipcode: "",
    showAddress: function() {
        return (street+city+zipcode);
    }
};

when I type:

address.showAddress();

It shows the error:

"Uncaught ReferenceError: street is not defined
    at Object.showAddress (index.js:237)
    at <anonymous>:1:

9"

I just googled the error and couldn't find a solution. at https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Errors/Not_defined I couln't understand why this error is happening in this scope. at developer .mozilla.org it is written that function can access all variables and functions defined inside the scope in which it is defined.

The question is:

why the member function can't access properties of it's own object. I studied oop concepts in javascript and there I can access properties of object easily by it's own method. I hope that the questio is clear.

about 4 years ago · Juan Pablo Isaza
1 Respuestas
Responde la pregunta

0

try this

You have to use a 'this' to use inside the key. If I'm right the only way is to use 'this'. Check the picture and write me if it work.

const address = {
street: "a",
city: "b",
zipcode: "c",
showAddress: function() {
    return (this.street+this.city+this.zipcode);
}

};

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