Path: csiph.com!usenet.pasdenom.info!news.albasani.net!news.teledata-fn.de!newsfeed.arcor.de!newsspool3.arcor-online.net!news.arcor.de.POSTED!not-for-mail Content-Type: text/plain; charset="UTF-8" Message-ID: <2053658.P1axspRLhA@PointedEars.de> From: Thomas 'PointedEars' Lahn Reply-To: Thomas 'PointedEars' Lahn Organization: PointedEars Software (PES) Date: Sun, 29 Dec 2013 17:45:05 +0100 User-Agent: KNode/4.11.3 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+&. MIME-Version: 1.0 Lines: 70 NNTP-Posting-Date: 29 Dec 2013 17:45:09 CET NNTP-Posting-Host: 2be31b47.newsspool1.arcor-online.net X-Trace: DXC=LHXXYVd2:ZK=8m7nZkdN^@ic==]BZ:afN4Fo<]lROoRAnkgeX?EC@@@0E8X5N4L0EBDZm8W4\YJNL[V>E In case anyone wants to see the actual code, here it is: > > // > // This code is supposed to initialize a slideshow over a > // particular image gallery. > // > function startShow(obj) { > > var elem = tag("li", obj); // Locate elements by tag > var gallery = id("gallery"); // Locate tag by ID > > for (var i = 0; i < elem.length; i++) new function() { > var cur = elem[i]; > setTimeout(function() { > showImage(cur); > setTimeout(function() { > fadeOut(gallery, 0, 10); > }, 3500); > }, i * 5000); > } > setTimeout(hideOverlay, 5000 * elem.length); > showOverlay(); > } > > I was just confused about the use of the "new function() {}" as > seen above. Hopefully someone can explain that to me. It is the result of the common misconception that it would be necessary to call a function as a *constructor* in order to create a private scope. Evidently it does not make sense to call this function as a constructor; it does not even use “this”. It is better written as follows: function startShow (obj) { /* Locate elements by tag _name_ */ var elem = tag("li", obj); /* Locate _element_ by ID */ var gallery = id("gallery"); for (var i = 0, len = elem.length; i < len; ++i) { (function (i) { var cur = elem[i]; window.setTimeout(function () { showImage(cur); window.setTimeout(function () { fadeOut(gallery, 0, 10); }, 3500); }, i * 5000); }(i)); } window.setTimeout(hideOverlay, 5000 * elem.length); showOverlay(); } Although these book reviews can be educational, it would take a lifetime explaining and correcting all of Resig's misconceptions. I have better things to do, and so should you. -- PointedEars Twitter: @PointedEars2 Please do not Cc: me. / Bitte keine Kopien per E-Mail.