Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.javascript > #15729

Re: XHR: Passing Parameters to a ready-state-change Function

From Jim T. <x@y.z>
Newsgroups comp.lang.javascript
Subject Re: XHR: Passing Parameters to a ready-state-change Function
Date 2012-09-05 20:55 -0400
Message-ID <3vsf48lt9uhh3qfddvcgbllllqj9hvquva@4ax.com> (permalink)
References <09ef48tfsgucbl7m49ggao3be5r0kb7v13@4ax.com> <hkhf48hfgl5qj69tsn82579raqj9cbgo6b@4ax.com> <v8rf48hqo7dppp25f3f9ocd8euu9bmseb6@4ax.com>

Show all headers | View raw


On Wed, 05 Sep 2012 17:30:39 -0700, Gene Wirchenko <genew@ocis.net>
wrote:

>On Wed, 05 Sep 2012 17:46:49 -0400, Jim T. <x@y.z> wrote:
>
>>On Wed, 05 Sep 2012 13:53:26 -0700, Gene Wirchenko <genew@ocis.net>
>>wrote:
>>
>>>Dear JavaScripters:
>>>
>>>     Is there any way to pass parameters to the ready-state-change
>>>function that checks the progress of a request?  I am currently using
>>>a global.  I would prefer not to.
>
>[snip]
>
>>Something like this maybe?
>>
>>oRequest.onreadystatechange=
>>    function()
>>    {
>>        var state = 0;
>>        
>>        return function()
>>                   {
>>                      state++;
>>
>>                      if ( state == 1)
>>                          <process data for scenario 1>
>>                     else
>>                          <process data for scenario 2>
>>                  };
>>    } ();
>
>     Uh, no.  The "1" and "2" in the names were not meant to imply any
>order.
>
>     I am working on the general design for Web pages which would
>allow CRUD.  Depending on the request to be performed, the result back
>from the server will be handled differently.  Request types could be
>in any order.
>
>     I also prefer to have each scenario broken out into its own
>function.  IMHO, debugging Web code is mucky enough without having
>longer-than-necessary functions.
>
>Sincerely,
>
>Gene Wirchenko

The main point was to eliminate global variables by using a closure.
The other details are up to you.

Here's the same thing, abstracted to they way you originally stated it

oRequest.onreadystatechange=
    function()
    {
        <state variables>
        
        return function()
                   {
                        <state change handling>
                         ProcessData();                         
                   };
    } ();

Back to comp.lang.javascript | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread


Thread

XHR: Passing Parameters to a ready-state-change Function Gene Wirchenko <genew@ocis.net> - 2012-09-05 13:53 -0700
  Re: XHR: Passing Parameters to a ready-state-change Function Jim T. <x@y.z> - 2012-09-05 17:46 -0400
    Re: XHR: Passing Parameters to a ready-state-change Function Gene Wirchenko <genew@ocis.net> - 2012-09-05 17:30 -0700
      Re: XHR: Passing Parameters to a ready-state-change Function Jim T. <x@y.z> - 2012-09-05 20:55 -0400
  Re: XHR: Passing Parameters to a ready-state-change Function Jim T. <x@y.z> - 2012-09-05 21:43 -0400
    Re: XHR: Passing Parameters to a ready-state-change Function Jim T. <x@y.z> - 2012-09-05 21:49 -0400
  Re: XHR: Passing Parameters to a ready-state-change Function Stefan Weiss <krewecherl@gmail.com> - 2012-09-06 18:56 +0200
    Re: XHR: Passing Parameters to a ready-state-change Function Gene Wirchenko <genew@ocis.net> - 2012-09-06 10:55 -0700
    Re: XHR: Passing Parameters to a ready-state-change Function Thomas 'PointedEars' Lahn <PointedEars@web.de> - 2012-09-06 21:38 +0200
      Re: XHR: Passing Parameters to a ready-state-change Function Thomas 'PointedEars' Lahn <PointedEars@web.de> - 2012-09-06 21:49 +0200
    Re: XHR: Passing Parameters to a ready-state-change Function Gene Wirchenko <genew@ocis.net> - 2012-09-06 15:49 -0700
      Re: XHR: Passing Parameters to a ready-state-change Function Tim Streater <timstreater@greenbee.net> - 2012-09-07 09:15 +0100
        Re: XHR: Passing Parameters to a ready-state-change Function Gene Wirchenko <genew@ocis.net> - 2012-09-07 09:58 -0700
          Re: XHR: Passing Parameters to a ready-state-change Function Tim Streater <timstreater@greenbee.net> - 2012-09-07 19:14 +0100
            Re: XHR: Passing Parameters to a ready-state-change Function cezary.tomczyk@gmail.com - 2012-09-07 13:51 -0700
              Re: XHR: Passing Parameters to a ready-state-change Function Thomas 'PointedEars' Lahn <PointedEars@web.de> - 2012-09-08 00:52 +0200
                Re: XHR: Passing Parameters to a ready-state-change Function cezary.tomczyk@gmail.com - 2012-09-07 16:32 -0700
                Re: XHR: Passing Parameters to a ready-state-change Function Thomas 'PointedEars' Lahn <PointedEars@web.de> - 2012-09-08 09:48 +0200
                Re: XHR: Passing Parameters to a ready-state-change Function Cezary Tomczyk <cezary.tomczyk@gmail.com> - 2012-09-08 02:09 -0700
                Re: XHR: Passing Parameters to a ready-state-change Function Tim Streater <timstreater@greenbee.net> - 2012-09-08 11:09 +0100
                Re: XHR: Passing Parameters to a ready-state-change Function Cezary Tomczyk <cezary.tomczyk@gmail.com> - 2012-09-08 03:39 -0700
                Re: XHR: Passing Parameters to a ready-state-change Function John G Harris <john@nospam.demon.co.uk> - 2012-09-08 15:00 +0100
            Re: XHR: Passing Parameters to a ready-state-change Function Thomas 'PointedEars' Lahn <PointedEars@web.de> - 2012-09-07 23:44 +0200
              Re: XHR: Passing Parameters to a ready-state-change Function Tim Streater <timstreater@greenbee.net> - 2012-09-07 23:08 +0100
                Re: XHR: Passing Parameters to a ready-state-change Function Thomas 'PointedEars' Lahn <PointedEars@web.de> - 2012-09-08 00:46 +0200
                Re: XHR: Passing Parameters to a ready-state-change Function Tim Streater <timstreater@greenbee.net> - 2012-09-08 11:11 +0100
                Re: XHR: Passing Parameters to a ready-state-change Function Thomas 'PointedEars' Lahn <PointedEars@web.de> - 2012-09-08 14:21 +0200
                Re: XHR: Passing Parameters to a ready-state-change Function Tim Streater <timstreater@greenbee.net> - 2012-09-08 17:06 +0100
                Re: XHR: Passing Parameters to a ready-state-change Function Thomas 'PointedEars' Lahn <PointedEars@web.de> - 2012-09-08 20:41 +0200
                Re: XHR: Passing Parameters to a ready-state-change Function Dr J R Stockton <reply1236@merlyn.demon.co.uk.invalid> - 2012-09-09 20:04 +0100
            Re: XHR: Passing Parameters to a ready-state-change Function Gene Wirchenko <genew@ocis.net> - 2012-09-09 18:40 -0700
              Re: XHR: Passing Parameters to a ready-state-change Function "Evertjan." <exxjxw.hannivoort@inter.nl.net> - 2012-09-10 07:21 +0000
              Re: XHR: Passing Parameters to a ready-state-change Function Tim Streater <timstreater@greenbee.net> - 2012-09-10 09:03 +0100
                Re: XHR: Passing Parameters to a ready-state-change Function "Evertjan." <exxjxw.hannivoort@inter.nl.net> - 2012-09-10 13:59 +0000
                Re: XHR: Passing Parameters to a ready-state-change Function Tim Streater <timstreater@greenbee.net> - 2012-09-10 15:35 +0100
                Re: XHR: Passing Parameters to a ready-state-change Function "Evertjan." <exxjxw.hannivoort@inter.nl.net> - 2012-09-10 22:42 +0000
                Re: XHR: Passing Parameters to a ready-state-change Function Scott Sauyet <scott.sauyet@gmail.com> - 2012-09-11 10:09 -0700
                Re: XHR: Passing Parameters to a ready-state-change Function Tim Streater <timstreater@greenbee.net> - 2012-09-11 22:42 +0100

csiph-web