Jump to content
Larry Ullman's Book Forums

Recommended Posts


I'm going over the "view.js" file on page 585 and in point 12 we have:

"bidAjax.onreadystatechange = handleBidAjaxResponse;"
why "()" is missing in the function call?
Why it is not like this:
"bidAjax.onreadystatechange = handleBidAjaxResponse();"


Link to post
Share on other sites

Because it's not a function call, it's a function reference.

Basically, you assign a function reference to the event handler so that when the event occurs (i.e., not now), the system knows which function to call.


If you assigned a function call to the event handler, then the function would be immediately executed, which would likely lead to an unintended result.


That make sense?

  • Upvote 1
Link to post
Share on other sites

Thanks for the answer…
Yes it does, It's described on page 245 of the book in "Functions as Variables Values" paragraph.

Basically in this line "bidAjax.onreadystatechange = handleBidAjaxResponse;" we are assigning value of function "handleBidAjaxResponse" to the property "onreadystatechange" of the object bidAjax.


Am I right?


Link to post
Share on other sites

Yes, that's right.


Furthermore, properties that have functions assigned to them are often called "methods", but that's purely a semantical differentiation from properties.

As a result though, assigning a function (not a function call) to onreadystatechange essentially makes onreadystatechange a method of the bidAjax object, and that method is called whenever the readystatechange event occurs for the bidAjax object.

Link to post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

  • Create New...