|
|
 |
 |
 |
 |
Javascript / Client Side Development
|
 |
 |
 |
 |
 |
 |
 |
 |
How can I make XMLHttpRequsts onreadystatechange a private method?
Hi all. I would like to take the onreadystatechange method, and make it private. Please could someone tell me what I need to do? I am guessing I'd need to somehow copy the constructor of the XMLHttpRequest object, into the prototype of an empty object and perhaps edit it from there? I would appreciate it if anyone could give me a quick example of how I might achieve this. In case anyone is wondering why I would like to do something like this, the reason is quite simple. For my needs, onreadystatechange should be made private, and it will be overridden by a function called onrequestcomplete. As I don't need to know the various stages of the communication with the server, I only want it to be passed to the external function for processing once it's complete. The onrequestcomplete method will also handle any errors the server might throw. Needless to say, that I am looking to create a custom object and not actually override anything on the original object itself. Many thanks in advance. Daz.
On May 11, 11:05 am, Daz <cutenfu@gmail.com> wrote:
> Hi all. > I would like to take the onreadystatechange method, and make it > private. Please could someone tell me what I need to do? I am guessing > I'd need to somehow copy the constructor of the XMLHttpRequest object, > into the prototype of an empty object and perhaps edit it from there? > I would appreciate it if anyone could give me a quick example of how I > might achieve this. > In case anyone is wondering why I would like to do something like > this, the reason is quite simple. > For my needs, onreadystatechange should be made private, and it will > be overridden by a function called onrequestcomplete. As I don't need > to know the various stages of the communication with the server, I > only want it to be passed to the external function for processing once > it's complete. The onrequestcomplete method will also handle any > errors the server might throw. > Needless to say, that I am looking to create a custom object and not > actually override anything on the original object itself. > Many thanks in advance. > Daz.
Just write a wrapper class that has a request object as a member, write what methods you need to expose, just call the appropriate one on the request object with the same arguments. If you need to expose properties use getters and setters. --- Geoff
On May 11, 9:37 pm, Geoffrey Summerhayes <sumr@gmail.com> wrote:
> On May 11, 11:05 am, Daz <cutenfu @gmail.com> wrote: > > Hi all. > > I would like to take the onreadystatechange method, and make it > > private. Please could someone tell me what I need to do? I am guessing > > I'd need to somehow copy the constructor of the XMLHttpRequest object, > > into the prototype of an empty object and perhaps edit it from there? > > I would appreciate it if anyone could give me a quick example of how I > > might achieve this. > > In case anyone is wondering why I would like to do something like > > this, the reason is quite simple. > > For my needs, onreadystatechange should be made private, and it will > > be overridden by a function called onrequestcomplete. As I don't need > > to know the various stages of the communication with the server, I > > only want it to be passed to the external function for processing once > > it's complete. The onrequestcomplete method will also handle any > > errors the server might throw. > > Needless to say, that I am looking to create a custom object and not > > actually override anything on the original object itself. > > Many thanks in advance. > > Daz. > Just write a wrapper class that has a request object as a > member, write what methods you need to expose, just > call the appropriate one on the request object with the same > arguments. If you need to expose properties use getters > and setters. > --- > Geoff
I suspected that that might have been what I needed to do. In fact, I've already done it, Hehe. I was just hoping that there might have been a better way using less codes and possibly using overrides. Many thanks for your response Geoff.
On May 11, 9:05 am, Daz <cutenfu@gmail.com> wrote: > For my needs, onreadystatechange should be made private, and it will > be overridden by a function called onrequestcomplete.
Lots of ajax kits already do this, why re-invent the wheel? My lib is at http://www.AjaxToolbox.com and might already be close to what you're trying to accomplish. Matt Kruse
|
 |
 |
 |
 |
|