Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 9109459
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T03:03:02+00:00 2026-06-17T03:03:02+00:00

In Head First Ajax, they give the following example: function getDetails(itemName) { request =

  • 0

In Head First Ajax, they give the following example:

function getDetails(itemName) {
  request = createRequest();
  if (request == null) {
    alert("Unable to create request");
    return;
  }
  var url= "getDetails.php?ImageID=" + escape(itemName);
  request.open("GET", url, true);
  request.onreadystatechange = displayDetails;//This references the function below
  request.send(null);
}

function displayDetails() {
  if (request.readyState == 4) {
    if (request.status == 200) {
      detailDiv = document.getElementById("description");
      detailDiv.innerHTML = request.responseText;
    }
  }
}

I’m curious what kind of construction is request.onreadystatechange = displayDetails;. The book says that “this is a reference to a function, not a function call”. However I don’t understand what this really means. I suppose it assigns the displayDetails function to the object request.onreadystatechange, but I don’t understand why or when to use this construction.

For example, what is the advantage of using this construction rather than doing something like:

request.onreadystatechange = function () {
  if (request.readyState == 4) {
    if (request.status == 200) {
      detailDiv = document.getElementById("description");
      detailDiv.innerHTML = request.responseText;
    }
  }
}

Also, is that an example of a functional language feature?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-17T03:03:02+00:00Added an answer on June 17, 2026 at 3:03 am

    Yes, that’s an example of a functional language feature. Functions are first-class citizens on those languages, meaning they can also be passed around, assigned to variables, etc.

    About your question on eventhandler = function () { } versus eventhandler = somefunc, you said:

    I suppose it assigns the displayDetails function to the object request.onreadystatechange, but I don’t understand why or when to use this construction

    The request object has a property called onreadystatechange, which represents an event handler function that should be called when the request’s readyState property changes. That’s why the book said it’s not a function call, but a reference assignment. You’re not calling the function when you assign it to request.onreadystatechange, it will be called only when that event happens. Clicks and all other events work like that (they’re basically asynchronous).

    It makes sense to use a function reference instead of an anonymous function assigment if you want to use the same handler for more than one event. For example, if you have two “save” buttons on two different parts of a web page, you can assign the same handler function to their click events.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am using AJAX/jQuery for the first time and am slowly getting my head
I'm playing with sample code from the book Head first Ajax. Here are the
I am reading Head First AJAX and became a little confused when I came
I have a basic AJAX form submission function in the head of my page
I am reading the Head First Android development book. In the third chapter where
Quote from Head first html: You can add padding to the top and bottom
I've read Head First Java, and I understand how OOP works. Here's my problem:
I'm diving head first into ASP MVC and am playing around with creating and
I am typing code from Head First iPhone Development (O'reilly) and Xcode will build
I am looking for another book beside Head First Servlets and JSP . The

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.