Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.javascript > #28565
| From | Thomas 'PointedEars' Lahn <PointedEars@web.de> |
|---|---|
| Newsgroups | comp.lang.javascript |
| Subject | Re: Javascript |
| Date | 2015-08-24 22:45 +0200 |
| Organization | PointedEars Software (PES) |
| Message-ID | <12751526.7etGybu6s3@PointedEars.de> (permalink) |
| References | <d43956e8-6f1d-431d-a45e-7845adf014ac@googlegroups.com> <XnsA4FF7286FD0DEeejj99@194.109.6.166> |
Evertjan. wrote:
> dil.nandoo@gmail.com wrote on 23 Aug 2015 in comp.lang.javascript:
>> <link type="text/css" rel="stylesheet" href="http://paste/map.css" />
>
> http://paste/ ???
>
> Is that a usable URL?
Probably yes, but not for the general public.
> "/>" are you using XML? Why?
You are jumping to conclusions. This is also Valid HTML5 syntax for the
“link” element, although the “/” is optional when one is not using the XHTML
syntax of HTML5.
>> for (i = 0; i <image_qtd; i++) {
>
> image_qtd is that defined somewhere?
More important: Is “i” declared? If not, this code will not run in strict
mode.
>> var preload = new Image();
>
> You are doing a var on every instance of the for,
> once is enough, because for does not make a closure.
Variables are instantiated once as execution enters a context, and because
the default scope is the execution context, not the Block statement (cf.
“let”), there is no intrinsic problem with putting the “var” statement in
the block adjacent to the “for” statement. Only that sometimes it is better
to declare a variable outside of the Block statement to see the relation
better if the variable is also used outside of the Block statement.
Some advocate declaring all variables on the top of an execution context,
some based on having an ill-defined notion of “hoisting”. I prefer to
declare my variables as close as possible to where they are first used, and
let linters take care of the rest (such as unused variables); which in the
case of a variable that is only used in a “for” loop to declare it in the
“for” statement or near the top of the adjacent Block statement, precisely
as the OP did.
--
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
Javascript dil.nandoo@gmail.com - 2015-08-22 20:03 -0700
Re: Javascript "Evertjan." <exxjxw.hannivoort@inter.nl.net> - 2015-08-23 11:15 +0200
Re: Javascript "Ralf S. Hellersen" <schneiderxr@arcor.de> - 2015-08-24 20:07 +0000
Re: Javascript "Evertjan." <exxjxw.hannivoort@inter.nl.net> - 2015-08-24 23:49 +0200
Re: Javascript Thomas 'PointedEars' Lahn <PointedEars@web.de> - 2015-08-24 22:45 +0200
Re: Javascript dil.nandoo@gmail.com - 2015-08-24 14:57 -0700
csiph-web