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

243
Visualizações
async function not being called in callback of another function

I have a simple class that loads in a google map, does some ajax and then on that response will eventually place some markers on the map, the class looks like, this,

class Map extends BaseComponent {

    constructor(element) {
        super(element);
        this._element = element;
        this.init();
    }
    
    init() {
        this.initialiseLoader();
    }

initialiseLoader(position = {}) {
        const loader = new Loader({
            apiKey: 'xxxxxxxx',
            version: 'weekly',
            libraries: []
        });

        loader.load()
            .then((google) => {
                this.map = new google.maps.Map(document.querySelector('.lta-map'), {
                    zoom:12
                });
                this.map.setCenter({
                    lat: Manipulator.getDataAttribute(document.querySelector('.lta-map'), 'latitude'),
                    lng: Manipulator.getDataAttribute(document.querySelector('.lta-map'), 'longitude')
                });
                this.placeMarkers();
                return true;
            })
            .catch((error) => { alert(error) });
    }

    async placeMarkers() {
        const markers = await Request.get(`${this.endpoint}?/latititude=${Manipulator.getDataAttribute(document.querySelector('.lta-map'), 'latitude')}&longitude=${ Manipulator.getDataAttribute(document.querySelector('.lta-map'), 'longitude')}`)
        .catch(() => { 
            console.log('error');
        });

        console.log(markers);
    }
}

The maps loads fine but when it hits the this.placeMarkers() call I get an error message claiming that,

this.placeMarkers is not a function

Is it because it's an async function?

about 4 years ago · Juan Pablo Isaza
1 Respostas
Responde à pergunta

0

make initialiseLoader(position = {}) and placeMarkers() arrow functions like this

initialiseLoader = (position = {}) => { yout code here ...}

placeMarkers = () => { your code here .. }

and maybe move placeMarkers inside initialiseLoader

Thats all i can think of

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