Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

356
Views
¿Por qué el método de mi clase de JavaScript no puede llamar a un método vecino?

Parece que el método buildGeoLocation() no puede ejecutar this.requestHandler() pero parece que no puedo entender por qué.
La consola muestra Uncaught TypeError: this.requestHandler is not a function .

A continuación se muestra mi código:

 class Geolocation { constructor() { this.elements = { section: document.querySelector('.james-section'), button: document.querySelector('.james-button'), } this.elements.button.addEventListener('click', this.buildGeoLocation) } buildGeoLocation() { Promise.all([ this.requestHandler("https://freegeoip.app/json/"), this.requestHandler("geolocation-template.html") ]).then(function(values) { const data = JSON.parse(values[0]); const markup = values[1] .replace('[ip]', data.ip) .replace('[city]', data.city) .replace('[country]', data.country_name) .replace('[lat]', data.latitude) .replace('[lng]', data.longitude); elements.section.innerHTML = markup; }).catch(function(reason) { console.log(reason); }); } requestHandler(url) { return new Promise(function(resolve, reject) { const xhttp = new XMLHttpRequest(); xhttp.onreadystatechange = function() { if(this.readyState == 4) { if(this.status == 200) { resolve(this.responseText); } else { reject('Call Failed'); } } }; xhttp.open("GET", url); xhttp.send(); }); } } new Geolocation;

Soy bastante nuevo en el uso de Clases, por lo que cualquier sugerencia sería muy apreciada 🙏

about 4 years ago · Juan Pablo Isaza
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!