Path: csiph.com!news.mixmin.net!weretis.net!feeder1.news.weretis.net!news.solani.org!.POSTED!not-for-mail From: Thomas 'PointedEars' Lahn Newsgroups: comp.lang.javascript Subject: Re: Javascript Date: Mon, 24 Aug 2015 22:45:41 +0200 Organization: PointedEars Software (PES) Lines: 49 Message-ID: <12751526.7etGybu6s3@PointedEars.de> References: Reply-To: Thomas 'PointedEars' Lahn Mime-Version: 1.0 Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: 8Bit X-Trace: solani.org 1440449356 21402 eJwNykkBwDAIBEBLnBuQEyj4l9DMe1zB6GNwmK8vJYdvfa2Sl7uVZyF1Kcomgs5gUl6ffD31Bx3hEOM= (24 Aug 2015 20:49:16 GMT) X-Complaints-To: abuse@news.solani.org NNTP-Posting-Date: Mon, 24 Aug 2015 20:49:16 +0000 (UTC) User-Agent: KNode/4.14.2 X-User-ID: eJwFwYEBwDAEBMCVCE9+HKH2H6F3sNDo9EA4FtuwnKU/oZWjhA93ZrVDIVzSUEg7HEmrq7j7pOzoaPZXP0KlFQQ= Cancel-Lock: sha1:fJoXD+JYxoOUXBHlSGRx8tZlzA0= X-NNTP-Posting-Host: eJwNx8kBwCAIBMCWWIVVyuGQ/ktI5je2CdZRGtXGJiEPiP7D5hJLva88roW3FjIgs0U8jq56/AAeOxEZ Xref: csiph.com comp.lang.javascript:28565 Evertjan. wrote: > dil.nandoo@gmail.com wrote on 23 Aug 2015 in comp.lang.javascript: >> > > 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 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: | SVN: Twitter: @PointedEars2 | ES Matrix: Please do not cc me. / Bitte keine Kopien per E-Mail.