Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.javascript > #27374
| Path | csiph.com!usenet.pasdenom.info!weretis.net!feeder1.news.weretis.net!news.solani.org!.POSTED!not-for-mail |
|---|---|
| From | Thomas 'PointedEars' Lahn <PointedEars@web.de> |
| Newsgroups | comp.lang.javascript |
| Subject | Re: XMLHttpRequest and Google Chrome |
| Date | Tue, 14 Apr 2015 22:51:40 +0200 |
| Organization | PointedEars Software (PES) |
| Lines | 98 |
| Message-ID | <2731864.3PV4tWIk7v@PointedEars.de> (permalink) |
| References | <mgedt0$ki9$1@dont-email.me> <mgg2bc$1olt$1@adenine.netfront.net> <mgg70i$19a$1@dont-email.me> <130420151317399772%timstreater@greenbee.net> <mggd3o$n6r$1@dont-email.me> <87h9skyte6.fsf@bsb.me.uk> <mggm7e$qbf$1@dont-email.me> <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> |
| Reply-To | Thomas 'PointedEars' Lahn <cljs@PointedEars.de> |
| Mime-Version | 1.0 |
| Content-Type | text/plain; charset="UTF-8" |
| Content-Transfer-Encoding | 8Bit |
| X-Trace | solani.org 1429044843 19806 eJwFwYEBwCAIA7CXRGit5yCD/09YAqexThAMDCa+q9ZlSpHtdRsC3sti2ghjln5811q9R/0DICQRQg== (14 Apr 2015 20:54:03 GMT) |
| X-Complaints-To | abuse@news.solani.org |
| NNTP-Posting-Date | Tue, 14 Apr 2015 20:54:03 +0000 (UTC) |
| User-Agent | KNode/4.14.2 |
| X-User-ID | eJwNwgkRADEIBDBLlG+pHCjgX8LdJCZ+/EHdXG1/TJUuz2q6c8X2dlncPKEASukskme7eLCRNpNBkQJiPPsAcKAWJw== |
| Cancel-Lock | sha1:Zvy3VHPjvmCkimx+j7TLNGNDtJA= |
| X-NNTP-Posting-Host | eJwFwYEBwDAEBMCVBP9hnKL2HyF3MB72dYKOxWqWdlyhfSnZUm2yE3ZcZqYatMmsQOnvDDwT/hDV |
| Xref | csiph.com comp.lang.javascript:27374 |
Show key headers only | View raw
Denis McMahon wrote:
> 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,
No, it calls that function as soon as execution reaches that statement.
Parsing always happens *before* execution in a computer program, in order to
build an abstract syntax tree out of the source code.
> and stores the return value of getCart in the onload attribute of the
> window object.
This is not Python. It is a _property_, not an attribute. Properties
*have* attributes in ECMAScript implementations, as have elements in markup
languages.
> 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.
Worse, in some environments (such as MSHTML) it is possible that the code
that would be executed after this statement is not executed because the
“undefined” value is not a proper value for an event-handler property (a
yellow triangle in the IE status bar would indicate that). As others said
before, either “null” or a reference to a Function instance is required.
Failure to do so has caused a runtime error in said environments (I had that
problem in particular, and reported on it here, when I switched the order of
property assignments in my code. That experience eventually lead me to
change my approach of using closures towards one more similar to the module
pattern, because that was less error-prone.)
> 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.
What is stored in the property is a _reference_ to a Function instance,
which is a callable object (implements the [[Call]] property). The
associated function is _not_ called by the window, but by browser code.
Proper, context-sensitive terminology is important to understand the
underlying concepts.
> 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.
There is no point in introducing a global variable here.
> p.s. The elf
My nickname has nothing to do with elves.
> will probably whine I'm wrong,
I am pointing out that you are wrong when you are wrong (which happens
rather often), so that those statements of you that are wrong are not
misleading other people as well.
> but if the code examples I posted work for you then I suggest you ignore
> him. He just enjoys waving his e-wang around and pretending he knows best.
Spoken like a true wannabe. You would be well-advised to shed your
arrogance and ignorance, and *listen* to what people have to say that have
considerably more experience in a field than you (and are still trying to
teach you something despite your ongoing impudence). For example, I have
been dealing with these languages for more than 17 years now. I wrote a
thesis on it, and defended it successfully. I am fortunate to have a great,
well-paid job that requires a deep understanding of them and their
applications. And you?
--
PointedEars
FAQ: <http://PointedEars.de/faq> | SVN: <http://PointedEars.de/wsvn/>
Twitter: @PointedEars2 | ES Matrix: <http://PointedEars.de/es-matrix>
Please do not cc me. / Bitte keine Kopien per E-Mail.
Back to comp.lang.javascript | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll 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