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


Groups > comp.lang.javascript > #27373

Re: XMLHttpRequest and Google Chrome

From Robbie Brown <rob@example.com>
Newsgroups comp.lang.javascript
Subject Re: XMLHttpRequest and Google Chrome
Date 2015-04-14 14:50 +0100
Organization A noiseless patient Spider
Message-ID <mgj5t1$ev3$1@dont-email.me> (permalink)
References (7 earlier) <mggock$rt7$1@solani.org> <mggqp5$cu6$1@dont-email.me> <130420151829307070%timstreater@greenbee.net> <mgh03o$3lk$1@dont-email.me> <mgj21e$e8r$2@dont-email.me>

Show all headers | View raw


On 14/04/15 13:43, Denis McMahon wrote:
> On Mon, 13 Apr 2015 18:59:13 +0100, Robbie Brown wrote:
>
>> if I change <head>
>>
>> <script type="text/javascript">
>> 	window.onload = getCart;
>> </script>
>>
>> The function doesn't get called, I get no "hello"
>> This is the same in all my browsers. I have no idea why as you and
>> others say that getCart should work, it simply doesn't. I'm not making
>> it up, it doesn't execute, I'm not mistaken, so, obviously something is
>> still missing.
>>
>> So it's back to the drawing board and javascript console.
>
> What you're missing is the previously explained "getCart should be a
> reference to a function".
>
> This code:
>
> <script type="text/javascript">
> 	window.onload = getCart();
> </script>
>
> runs the getCart function as soon as the parser finds it, and stores the
> return value of getCart in the onload attribute of the window object.
> When the window finishes loading, it attempts to call the stored value as
> if it were a function, which does nothing because getCart doesn't return
> a function object.
>
> This code:
>
> <script type="text/javascript">
> 	window.onload = function() {getCart();};
> </script>
>
> stores a function that calls getCart() in the onload attribute of the
> window object. When the window finishes loading, it attempts to call the
> stored value as if it were a function, which works because what has been
> stored is actually a function.
>
> This code:
>
> <script type="text/javascript">
>          var bing = function() {getCart();};
> 	window.onload = bing;
> </script>
>
> stores the function object in the variable named bing, and then stores
> bing in the onload attribute of the window object. When the window
> finishes loading, it attempts to call the stored value as if it were a
> function, which works because what has been stored is actually a function.

Yes, thanks, I've got this now.

I've spent my entire working life writing in compiled languages where 
calling a function or method always requires the use of parentheses. 
What I was missing is the exact semantics of window.onload, I do get it 
now, the light came on when I did this

<script>
    onload=foo;
    onload=bar;
</script>

and only bar was executed

(loud clunk as the penny dropped)

Hey, I thought, how about

<script>
    func baz(){
       foo();
       bar();
    }
</script>

This is much more familiar.

Now

<script>
    onload=baz;
</script>

Does the business

many thanks for your detailed description.

<snip>

Rob

-- 
Not floundering ... just fishing

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


Thread

XMLHttpRequest and Google Chrome Robbie Brown <rob@example.com> - 2015-04-12 19:36 +0100
  Re: XMLHttpRequest and Google Chrome JJ <jj4public@vfemail.net> - 2015-04-13 12:33 +0700
    Re: XMLHttpRequest and Google Chrome Robbie Brown <rob@example.com> - 2015-04-13 07:41 +0100
  Re: XMLHttpRequest and Google Chrome Martin Honnen <mahotrash@yahoo.de> - 2015-04-13 11:30 +0200
    Re: XMLHttpRequest and Google Chrome Robbie Brown <rob@example.com> - 2015-04-13 11:50 +0100
      Re: XMLHttpRequest and Google Chrome Tim Streater <timstreater@greenbee.net> - 2015-04-13 13:17 +0100
        Re: XMLHttpRequest and Google Chrome Robbie Brown <rob@example.com> - 2015-04-13 13:34 +0100
          Re: XMLHttpRequest and Google Chrome Tim Streater <timstreater@greenbee.net> - 2015-04-13 14:26 +0100
          Re: XMLHttpRequest and Google Chrome Martin Honnen <mahotrash@yahoo.de> - 2015-04-13 16:15 +0200
            Re: XMLHttpRequest and Google Chrome Robbie Brown <rob@example.com> - 2015-04-13 16:03 +0100
              Re: XMLHttpRequest and Google Chrome Martin Honnen <mahotrash@yahoo.de> - 2015-04-13 19:26 +0200
                Re: XMLHttpRequest and Google Chrome "Christoph M. Becker" <cmbecker69@arcor.de> - 2015-04-13 20:23 +0200
          Re: XMLHttpRequest and Google Chrome Ben Bacarisse <ben.usenet@bsb.me.uk> - 2015-04-13 15:50 +0100
            Re: XMLHttpRequest and Google Chrome Robbie Brown <rob@example.com> - 2015-04-13 16:10 +0100
              Re: XMLHttpRequest and Google Chrome "Christoph M. Becker" <cmbecker69@arcor.de> - 2015-04-13 17:46 +0200
                Re: XMLHttpRequest and Google Chrome Robbie Brown <rob@example.com> - 2015-04-13 17:28 +0100
                Re: XMLHttpRequest and Google Chrome "Christoph M. Becker" <cmbecker69@arcor.de> - 2015-04-13 19:14 +0200
                Re: XMLHttpRequest and Google Chrome Tim Streater <timstreater@greenbee.net> - 2015-04-13 18:29 +0100
                Re: XMLHttpRequest and Google Chrome Robbie Brown <rob@example.com> - 2015-04-13 18:59 +0100
                Re: XMLHttpRequest and Google Chrome "Christoph M. Becker" <cmbecker69@arcor.de> - 2015-04-13 20:29 +0200
                Re: XMLHttpRequest and Google Chrome Tim Streater <timstreater@greenbee.net> - 2015-04-13 19:34 +0100
                Re: XMLHttpRequest and Google Chrome Robbie Brown <rob@example.com> - 2015-04-13 20:11 +0100
                Re: XMLHttpRequest and Google Chrome "Evertjan." <exxjxw.hannivoort@inter.nl.net> - 2015-04-13 20:44 +0200
                Re: XMLHttpRequest and Google Chrome Robbie Brown <rob@example.com> - 2015-04-13 20:21 +0100
                Re: XMLHttpRequest and Google Chrome Denis McMahon <denismfmcmahon@gmail.com> - 2015-04-14 12:43 +0000
                Re: XMLHttpRequest and Google Chrome Robbie Brown <rob@example.com> - 2015-04-14 14:50 +0100
                Re: XMLHttpRequest and Google Chrome Thomas 'PointedEars' Lahn <PointedEars@web.de> - 2015-04-14 22:51 +0200
                Re: XMLHttpRequest and Google Chrome Thomas 'PointedEars' Lahn <PointedEars@web.de> - 2015-04-13 22:28 +0200
  Re: XMLHttpRequest and Google Chrome Robbie Brown <rob@example.com> - 2015-04-13 19:23 +0100
    Re: XMLHttpRequest and Google Chrome Tim Streater <timstreater@greenbee.net> - 2015-04-13 19:38 +0100
  Re: XMLHttpRequest and Google Chrome "Leonardo Azpurua" <leonardo@exmvps.org> - 2015-04-13 17:36 -0430
  Re: XMLHttpRequest and Google Chrome Robbie Brown <rob@example.com> - 2015-04-14 11:35 +0100
  Re: XMLHttpRequest and Google Chrome Denis McMahon <denismfmcmahon@gmail.com> - 2015-04-14 11:37 +0000

csiph-web