how to access method variables from within an anonomous function in javascript

Posted by Hussain on Stack Overflow See other posts from Stack Overflow or by Hussain
Published on 2010-05-23T21:54:00Z Indexed on 2010/05/23 22:01 UTC
Read the original article Hit count: 202

Filed under:
|
|
|

I'm writing a small ajax class for personal use. In the class, I have a "post" method for sending post requests. The post method has a callback parameter. In the onreadystatechange propperty, I need to call the callback method.

Something like this:

this.requestObject.onreadystatechange = function() {
    callback(this.responseText); 
}

However, I can't access the callback variable from within the anonomous function. How can I bring the callback variable into the scope of the onreadystatechange anonomous function?

© Stack Overflow or respective owner

Related posts about JavaScript

Related posts about AJAX