zibrnp 0 Posted March 16, 2014 Report Share Posted March 16, 2014 Hello,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();"Thanks Quote Link to post Share on other sites
HartleySan 826 Posted March 16, 2014 Report Share Posted March 16, 2014 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? 1 Quote Link to post Share on other sites
zibrnp 0 Posted March 16, 2014 Author Report Share Posted March 16, 2014 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? Thanks Quote Link to post Share on other sites
HartleySan 826 Posted March 16, 2014 Report Share Posted March 16, 2014 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. Quote Link to post Share on other sites
Recommended Posts
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.