Create an Account
username: password:
 
  MemeStreams Logo

MemeStreams Discussion

search


This page contains all of the posts and discussion on MemeStreams referencing the following web page: Encapsulating XmlHttpRequest Calls within JavaScript classes. You can find discussions on MemeStreams as you surf the web, even if you aren't a MemeStreams member, using the Threads Bookmarklet.

Encapsulating XmlHttpRequest Calls within JavaScript classes
by Acidus at 1:42 pm EST, Dec 11, 2006

Or, solving the scope issue of callback functions without resorting to global variables!

//set the var so we can scope the callback var _this = this;
//callback will be an anonymous function that calls back into our class
//this allows the call back in which we handle the response (_onData())
// to have the correct scope.
this._request.onreadystatechange = function(){_this._onData()};


 
RE: Encapsulating XmlHttpRequest Calls within JavaScript classes
by Lost at 6:29 pm EST, Dec 11, 2006

Acidus wrote:
Or, solving the scope issue of callback functions without resorting to global variables!

//set the var so we can scope the callback var _this = this; //callback will be an anonymous function that calls back into our class //this allows the call back in which we handle the response (_onData()) // to have the correct scope. this._request.onreadystatechange = function(){_this._onData()};

Aye, I started doing this once someone on ##javascript on freenode told me so.


 
 
Powered By Industrial Memetics