Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.javascript > #14248
| From | Dr J R Stockton <reply1222@merlyn.demon.co.uk.not.invalid> |
|---|---|
| Newsgroups | comp.lang.javascript |
| Subject | Re: 'undefined' in declaration of function |
| Date | 2012-05-30 20:06 +0100 |
| Organization | Home |
| Message-ID | <+GbAIoKS$mxPFwJW@invalid.uk.co.demon.merlyn.invalid> (permalink) |
| References | <adf008c0-39de-4eef-9dc3-d687899f6f7c@googlegroups.com> <617c6390-5eea-43e2-881b-0fb60bb62e46@t35g2000yqd.googlegroups.com> |
In comp.lang.javascript message <617c6390-5eea-43e2-881b-0fb60bb62e46@t3 5g2000yqd.googlegroups.com>, Tue, 29 May 2012 05:30:44, Scott Sauyet <scott.sauyet@gmail.com> posted: >One silly flaw in Javascript that would probably have been removed had >the language not been standardized so quickly is that `undefined` is >not a keyword like `null`. It is simply a global property. Arbitrary >code can overwrite it. So a library like jQuery that's operating in a >very heterogeneous environment cannot assume that no other code has >overwritten that property. This is one way to restore it. Inside the >function, `undefined` is now pointing to the value of the second >parameter passed to the function. Since we don't pass a parameter >there, the value is undefined, exactly what we want the `undefined` >property to represent. Note that this does *not* override the global >property; it simply shadows it. Outside this function, everything >reverts to the way it was (except that any functions which close over >`undefined` will also have the shadowing version [and if that doesn't >make any sense to you, don't worry about it for now.]) > >There are other ways this could be done, but this one is common, and I >don't see any major flaws with it? Other opinions? The routine is then relying on something external to itself, its call. I have used var U within the routine, with U on one side of == or != tests, with success; possibly === or !== tests would be safer; I don't generally use U for any other purpose when confusion might occur. -- (c) John Stockton, nr London, UK. ?@merlyn.demon.co.uk Turnpike v6.05 MIME. Web <http://www.merlyn.demon.co.uk/> - FAQqish topics, acronyms and links; Astro stuff via astron-1.htm, gravity0.htm ; quotings.htm, pascal.htm, etc. No Encoding. Quotes before replies. Snip well. Write clearly. Don't Mail News.
Back to comp.lang.javascript | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread
'undefined' in declaration of function trunikov <dmitry.trunikov@gmail.com> - 2012-05-29 04:58 -0700
Re: 'undefined' in declaration of function Scott Sauyet <scott.sauyet@gmail.com> - 2012-05-29 05:30 -0700
Re: 'undefined' in declaration of function trunikov <dmitry.trunikov@gmail.com> - 2012-05-29 05:44 -0700
Re: 'undefined' in declaration of function Dr J R Stockton <reply1222@merlyn.demon.co.uk.not.invalid> - 2012-05-30 20:06 +0100
Re: 'undefined' in declaration of function Scott Sauyet <scott.sauyet@gmail.com> - 2012-05-31 05:22 -0700
csiph-web