Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

180
Visualizações
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 Respostas
Responde à pergunta

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 Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda