Path: csiph.com!x330-a1.tempe.blueboxinc.net!usenet.pasdenom.info!gegeweb.42!gegeweb.eu!nntpfeed.proxad.net!proxad.net!feeder2-2.proxad.net!newsfeed.arcor.de!newsspool3.arcor-online.net!news.arcor.de.POSTED!not-for-mail Content-Type: text/plain; charset="ISO-8859-1" Message-ID: <1634456.94akUBOfGJ@PointedEars.de> From: Thomas 'PointedEars' Lahn Reply-To: Thomas 'PointedEars' Lahn Organization: PointedEars Software (PES) Date: Mon, 14 Nov 2011 17:24:15 +0100 User-Agent: KNode/4.4.11 Content-Transfer-Encoding: 7Bit Subject: Re: Difference between findPos("divThis") and findPos(divThis) Newsgroups: comp.lang.javascript References: <4775241.ypaU67uLZW@PointedEars.de> <2394720.ArG6xLiZAS@PointedEars.de> <8932764.SEqChMirdb@PointedEars.de> Followup-To: comp.lang.javascript MIME-Version: 1.0 Lines: 110 NNTP-Posting-Date: 14 Nov 2011 17:24:16 CET NNTP-Posting-Host: 21cdc37a.newsspool3.arcor-online.net X-Trace: DXC=N_dbMIC0ki?;]cDoEWD6A4McF=Q^Z^V384Fo<]lROoR18kF 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, (2004)