Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.javascript > #8320
| Message-ID | <1634456.94akUBOfGJ@PointedEars.de> (permalink) |
|---|---|
| From | Thomas 'PointedEars' Lahn <PointedEars@web.de> |
| Organization | PointedEars Software (PES) |
| Date | 2011-11-14 17:24 +0100 |
| Subject | Re: Difference between findPos("divThis") and findPos(divThis) |
| Newsgroups | comp.lang.javascript |
| References | (6 earlier) <j9pb43$ah2$2@speranza.aioe.org> <j9pf87$rka$1@dont-email.me> <j9phhk$s3i$1@speranza.aioe.org> <8932764.SEqChMirdb@PointedEars.de> <j9raj8$ft3$1@speranza.aioe.org> |
| Followup-To | comp.lang.javascript |
Followups directed to: comp.lang.javascript
J.R. wrote: > On 14/11/2011 10:15, Thomas 'PointedEars' Lahn wrote: >>>> var el = (typeof obj == 'string') ? document.getElementById(obj) : obj; >>>> w = el.offsetWidth ; >>>> h = el.offsetHeight; >>>> ... >>>> >>> >>> No, because the ";" marks the end of the variable declaration list. In >>> the above code, you are indeed creating an implied global variable >>> called h, >> >> No, it creates, if it succeeds (and does not throw an exception, as >> observed in some instances with MSHTML before, and required in ECMAScript >> Ed. 5 strict mode), a property with that name of the ECMAScript Global >> object or overwrites a property with that name of an object in the scope >> chain. > > Considering only the given code by Cal, it creates two implied global > variables (w and h), No. What happens is what I described, which is compliant with ECMAScript Edition 3 Final, sections 11.13.1 and 8.6.2, and Editions 5 and 5.1, sections 11.13.1 and 8.7.2, respectively. > according to ECMA-262 3rd, section 12.2: The current edition of ECMAScript is 5.1, June 2011 CE; not Edition 3 (Final), December 1999/March 2000 CE. > "If the variable statement occurs inside a FunctionDeclaration, the > variables are defined with function-local scope in that function, as > described in s10.1.3. Otherwise, they are defined with *global scope* > (that is, they are created as members of the global object, as described > in 10.1.3) [...]" That section's second sentence refers to *variable statements* outside of a FunctionDeclaration, as made obvious by its first sentence. >>> instead of creating a private variable in the function scope. >> The proper terminology here is "_local_ variable", not what you wrote. > > As written above, the correct terminology is indeed "variable defined in > the function-local scope". No, a "variable defined *with* function-local scope" is something else than "a variable defined *in* the function-local scope" (which you also did not say before). The proper term for such a variable is _local_ variable, _not_ a "private" variable (whereas you said the latter before). >> Visibility modifiers do not exist in these implementations; privacy can >> only be achieved implicitly, through closures. So far there is no >> closure in that code regarding those variables. > > ACK, except for the *only*. Please name a counter-example using ECMAScript-conforming code where a `private'-like property visibility is achieved explicitly. >>> it is one of the JavaScript best practices to declare all of the >>> variables used in a function at the top of the function body. You may >>> have many variables separated by commas, e.g >>> >>> var el = ..., >>> h = ..., >>> w = ..., >>> i, j, len, ..., z; >>> >>> You must not use multiple var statements such as: >>> var el; >>> var h = ...; >>> var z; >> >> Wrong. In fact, it turns out that syntactically *correct*, adjacent >> `var' statements work better with editors capable of refactoring, such as >> Eclipse JSDT. > > It's not wrong, it's a different approach instead. No, it is wrong to say "must not use". "Must not" in English means "is not allowed to". It is certainly allowed to use that syntactical construct, as it constitutes nothing more than consecutive statements. > ECMAScript permits using either a single var or many var statements as one > wishes. That is not what you said before. > I prefer the single var pattern. That is also not what you said before. > And I don't care about Eclipse - I'm talking about JavaScript not JAVA. Will you please at least *try* get yourself educated before you post? Eclipse JSDT is the Eclipse _JavaScript_ Development Tools plugin. > Personally, I prefer Python / Django but it doesn't matter to this > discussion anyway. Yes, it matters how a commonly used JavaScript IDE can deal with either of those syntactical constructs. PointedEars -- Danny Goodman's books are out of date and teach practices that are positively harmful for cross-browser scripting. -- Richard Cornford, cljs, <cife6q$253$1$8300dec7@news.demon.co.uk> (2004)
Back to comp.lang.javascript | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread
Difference between findPos("divThis") and findPos(divThis) " Cal Who" <CalWhoNOSPAM@roadrunner.com> - 2011-11-13 09:51 -0500
Re: Difference between findPos("divThis") and findPos(divThis) Thomas 'PointedEars' Lahn <PointedEars@web.de> - 2011-11-13 18:25 +0100
Re: Difference between findPos("divThis") and findPos(divThis) " Cal Who" <CalWhoNOSPAM@roadrunner.com> - 2011-11-13 13:58 -0500
Re: Difference between findPos("divThis") and findPos(divThis) Thomas 'PointedEars' Lahn <PointedEars@web.de> - 2011-11-13 20:26 +0100
Re: Difference between findPos("divThis") and findPos(divThis) " Cal Who" <CalWhoNOSPAM@roadrunner.com> - 2011-11-13 15:04 -0500
Re: Difference between findPos("divThis") and findPos(divThis) "J.R." <groups_jr-1@yahoo.com.br> - 2011-11-13 18:55 -0200
Re: Difference between findPos("divThis") and findPos(divThis) "J.R." <groups_jr-1@yahoo.com.br> - 2011-11-13 18:59 -0200
Re: Difference between findPos("divThis") and findPos(divThis) " Cal Who" <CalWhoNOSPAM@roadrunner.com> - 2011-11-13 17:10 -0500
Re: Difference between findPos("divThis") and findPos(divThis) "J.R." <groups_jr-1@yahoo.com.br> - 2011-11-13 20:49 -0200
Re: Difference between findPos("divThis") and findPos(divThis) " Cal Who" <CalWhoNOSPAM@roadrunner.com> - 2011-11-13 20:00 -0500
Re: Difference between findPos("divThis") and findPos(divThis) Denis McMahon <denismfmcmahon@gmail.com> - 2011-11-14 02:37 +0000
Re: Difference between findPos("divThis") and findPos(divThis) "J.R." <groups_jr-1@yahoo.com.br> - 2011-11-14 03:14 -0200
Re: Difference between findPos("divThis") and findPos(divThis) Denis McMahon <denismfmcmahon@gmail.com> - 2011-11-14 14:03 +0000
Re: Difference between findPos("divThis") and findPos(divThis) "J.R." <groups_jr-1@yahoo.com.br> - 2011-11-14 14:14 -0200
Re: Difference between findPos("divThis") and findPos(divThis) Denis McMahon <denismfmcmahon@gmail.com> - 2011-11-14 18:31 +0000
Re: Difference between findPos("divThis") and findPos(divThis) "Evertjan." <exjxw.hannivoort@interxnl.net> - 2011-11-14 18:36 +0000
Re: Difference between findPos("divThis") and findPos(divThis) Denis McMahon <denismfmcmahon@gmail.com> - 2011-11-15 00:18 +0000
Re: Difference between findPos("divThis") and findPos(divThis) Scott Sauyet <scott.sauyet@gmail.com> - 2011-11-14 10:54 -0800
Re: Difference between findPos("divThis") and findPos(divThis) "Richard Cornford" <Richard@litotes.demon.co.uk> - 2011-11-15 01:23 +0000
Re: Difference between findPos("divThis") and findPos(divThis) Scott Sauyet <scott.sauyet@gmail.com> - 2011-11-16 06:04 -0800
Re: Difference between findPos("divThis") and findPos(divThis) Frobernik <nospam@nospam.com> - 2011-11-17 22:06 +0000
Re: Difference between findPos("divThis") and findPos(divThis) Thomas 'PointedEars' Lahn <PointedEars@web.de> - 2011-11-17 23:54 +0100
Re: Difference between findPos("divThis") and findPos(divThis) Frobernik <nospam@nospam.com> - 2011-11-18 09:33 +0000
Function arguments vs. local variables (was: Difference between findPos("divThis") and findPos(divThis)) Thomas 'PointedEars' Lahn <PointedEars@web.de> - 2011-11-19 16:05 +0100
Re: Function arguments vs. local variables Thomas 'PointedEars' Lahn <PointedEars@web.de> - 2011-11-19 18:17 +0100
Re: Function arguments vs. local variables Frobernik <nospam@nospam.com> - 2011-11-21 20:01 +0000
Re: Function arguments vs. local variables Thomas 'PointedEars' Lahn <PointedEars@web.de> - 2011-11-22 12:50 +0100
Re: Difference between findPos("divThis") and findPos(divThis) Thomas 'PointedEars' Lahn <PointedEars@web.de> - 2011-11-14 15:04 +0100
Re: Difference between findPos("divThis") and findPos(divThis) John G Harris <john@nospam.demon.co.uk> - 2011-11-14 15:13 +0000
Re: Difference between findPos("divThis") and findPos(divThis) Thomas 'PointedEars' Lahn <PointedEars@web.de> - 2011-11-14 18:27 +0100
Re: Difference between findPos("divThis") and findPos(divThis) Eric Bednarz <bednarz@fahr-zur-hoelle.org> - 2011-11-14 17:52 +0100
Re: Difference between findPos("divThis") and findPos(divThis) "J.R." <groups_jr-1@yahoo.com.br> - 2011-11-14 15:07 -0200
Re: Difference between findPos("divThis") and findPos(divThis) Thomas 'PointedEars' Lahn <PointedEars@web.de> - 2011-11-14 18:19 +0100
Re: Difference between findPos("divThis") and findPos(divThis) "J.R." <groups_jr-1@yahoo.com.br> - 2011-11-14 15:44 -0200
Re: Difference between findPos("divThis") and findPos(divThis) Thomas 'PointedEars' Lahn <PointedEars@web.de> - 2011-11-14 19:01 +0100
Re: Difference between findPos("divThis") and findPos(divThis) "J.R." <groups_jr-1@yahoo.com.br> - 2011-11-14 16:42 -0200
Re: Difference between findPos("divThis") and findPos(divThis) Thomas 'PointedEars' Lahn <PointedEars@web.de> - 2011-11-14 19:53 +0100
Re: Difference between findPos("divThis") and findPos(divThis) Richard Cornford <Richard@litotes.demon.co.uk> - 2011-11-14 09:18 -0800
Re: Difference between findPos("divThis") and findPos(divThis) "J.R." <groups_jr-1@yahoo.com.br> - 2011-11-14 16:22 -0200
Re: Difference between findPos("divThis") and findPos(divThis) Denis McMahon <denismfmcmahon@gmail.com> - 2011-11-14 18:38 +0000
Re: Difference between findPos("divThis") and findPos(divThis) Gene Wirchenko <genew@ocis.net> - 2011-11-14 12:12 -0800
Re: Difference between findPos("divThis") and findPos(divThis) Gene Wirchenko <genew@ocis.net> - 2011-11-14 12:00 -0800
Re: Difference between findPos("divThis") and findPos(divThis) " Cal Who" <CalWhoNOSPAM@roadrunner.com> - 2011-11-14 08:48 -0500
Re: Difference between findPos("divThis") and findPos(divThis) Thomas 'PointedEars' Lahn <PointedEars@web.de> - 2011-11-14 13:15 +0100
Re: Difference between findPos("divThis") and findPos(divThis) "J.R." <groups_jr-1@yahoo.com.br> - 2011-11-14 13:03 -0200
Re: Difference between findPos("divThis") and findPos(divThis) Thomas 'PointedEars' Lahn <PointedEars@web.de> - 2011-11-14 17:24 +0100
Re: Difference between findPos("divThis") and findPos(divThis) Thomas 'PointedEars' Lahn <PointedEars@web.de> - 2011-11-14 13:00 +0100
Re: Difference between findPos("divThis") and findPos(divThis) John G Harris <john@nospam.demon.co.uk> - 2011-11-14 15:05 +0000
csiph-web