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

265
Views
What type of function is this?
const xhr = new XMLHttpRequest(),
    method = "GET",
    url = "https://developer.mozilla.org/";

xhr.open(method, url, true);
xhr.onreadystatechange = function () {
  // In local files, status is 0 upon success in Mozilla Firefox
  if(xhr.readyState === XMLHttpRequest.DONE) {
    var status = xhr.status;
    if (status === 0 || (status >= 200 && status < 400)) {
      // The request has been completed successfully
      console.log(xhr.responseText);
    } else {
      // Oh no! There has been an error with the request!
    }
  }
};
xhr.send();

This code represent an XHR request and response. I was watching a tutorial on AJAX and xhr.onreadystatechange was described as an object property. I know that function expressions are anonymous functions assigned to variables but what about anonymous functions assigned to object properties. What is the name of this kind of function that is called when an object property updates? This hasn’t really been taught in basic javascript or ES6 from what I can see.

about 4 years ago · Juan Pablo Isaza
2 answers
Answer question

0

The function that you are assigning to xhr.onreadystatechange is called an event handler. This event handler function gets executed when the actual event 'readystatechange' gets fired in your case.

about 4 years ago · Juan Pablo Isaza Report

0

That is a event handler which differs a little bit from a callback.

about 4 years ago · Juan Pablo Isaza Report
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!