Path: csiph.com!v102.xanadu-bbs.net!xanadu-bbs.net!feeder.erje.net!eu.feeder.erje.net!newsfeed.fsmpi.rwth-aachen.de!uucp.gnuu.de!newsfeed.arcor.de!newsspool2.arcor-online.net!news.arcor.de.POSTED!not-for-mail Content-Type: text/plain; charset="UTF-8" Message-ID: <3145125.oXMAan8fah@PointedEars.de> From: Thomas 'PointedEars' Lahn Reply-To: Thomas 'PointedEars' Lahn Organization: PointedEars Software (PES) Date: Wed, 28 Aug 2013 11:04:07 +0200 User-Agent: KNode/4.10.5 Content-Transfer-Encoding: 8Bit X-Face: %i>XG-yXR'\"2P/C_aO%~;2o~?g0pPKmbOw^=NT`tprDEf++D.m7"}HW6.#=U:?2GGctkL,f89@H46O$ASoW&?s}.k+&. <2725916.yAnYnyUf7L@PointedEars.de> MIME-Version: 1.0 Lines: 45 NNTP-Posting-Date: 28 Aug 2013 11:04:07 CEST NNTP-Posting-Host: 3642400a.newsspool1.arcor-online.net X-Trace: DXC=EKX3W_0BolcOKO]LCQ@0g`ic==]BZ:afn4Fo<]lROoRankgeX?EC@@`\BGGOn[Md>hDZm8W4\YJNlb@mF9jNikdemA0dJ;NON0o;XEDKi:A6S` X-Complaints-To: usenet-abuse@arcor.de Xref: csiph.com comp.lang.javascript:21076 Thomas 'PointedEars' Lahn wrote: > Ken wrote: >> function loadImages(imgs, callback) { >> >> var i = 0, img, count = imgs.length, result = []; >> >> /// create images >> for(; img = imgs[i]; i++) { > > That is awful code style for array iteration, in probably every language > of the C family. Consider this instead: > > for (var i = 0, count = len = imgs.length; i < len; ++i) > { Considered and rejected :) This creates an “implied global”, “len” (a ReferenceError in strict mode). It would have to be, for example var count; for (var i = 0, len = count = imgs.length; i < len; ++i) to fix that. var count = 0; for (var i = 0, len = imgs.length; i < len; ++i) and counting “count” up would work, too. If order does not matter, var count; for (var i = count = imgs.length; i--;) and counting “count” down is an optimization to consider. (Even though there is no block scoping with “var”, it is useful to keep the declarations of variables that are only used in the loop close to the loop.) -- PointedEars Twitter: @PointedEars2 Please do not Cc: me. / Bitte keine Kopien per E-Mail.