Path: csiph.com!usenet.pasdenom.info!weretis.net!feeder1.news.weretis.net!news.solani.org!.POSTED!not-for-mail From: Thomas 'PointedEars' Lahn 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> References: <130420151317399772%timstreater@greenbee.net> <87h9skyte6.fsf@bsb.me.uk> <130420151829307070%timstreater@greenbee.net> Reply-To: Thomas 'PointedEars' Lahn 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 Denis McMahon wrote: > What you're missing is the previously explained "getCart should be a > reference to a function". > > This code: > > > > 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: > > > > 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: > > > > 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: | SVN: Twitter: @PointedEars2 | ES Matrix: Please do not cc me. / Bitte keine Kopien per E-Mail.