Path: csiph.com!optima2.xanadu-bbs.net!xanadu-bbs.net!feeder.erje.net!1.eu.feeder.erje.net!weretis.net!feeder1.news.weretis.net!news.solani.org!.POSTED!not-for-mail From: Thomas 'PointedEars' Lahn Newsgroups: comp.lang.javascript Subject: Re: Retrieve a select from a table cell Date: Wed, 15 Jul 2015 00:23:38 +0200 Organization: PointedEars Software (PES) Lines: 68 Message-ID: <5385669.KCYVbj6BcG@PointedEars.de> References: <3951517.CJbgAzKFgc@PointedEars.de> Reply-To: Thomas 'PointedEars' Lahn Mime-Version: 1.0 Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: 8Bit X-Trace: solani.org 1436912806 14062 eJwFwYkBwEAEBMCWvItyxNF/CZlxBWPC4DA/v23pKKECsINdPrI3dx4VOpYqM19l00tWrh8izRES (14 Jul 2015 22:26:46 GMT) X-Complaints-To: abuse@news.solani.org NNTP-Posting-Date: Tue, 14 Jul 2015 22:26:46 +0000 (UTC) User-Agent: KNode/4.14.2 X-User-ID: eJwFwQUBADAIALBKcDwO2j/CNyFFbWMVZTm5TJeMM+e6xjWqdRyH2BsbqacxPfNsc4C8LJiBTns7HB9/fBsWPA== Cancel-Lock: sha1:T2ldblxJqE2MrPNtV6t9VLWCLwI= X-NNTP-Posting-Host: eJwNxsEBwCAIA8CVQEiQdcRm/xHsvQ5B51QSTAha6bQbuLu6hfnLWvqCnbGNDivl0ehEZfUD/9wQMA== Xref: csiph.com comp.lang.javascript:28424 Joao Rodrigues wrote: > Em 14/07/2015 17:07, Thomas 'PointedEars' Lahn escreveu: >> Joao Rodrigues wrote: >>> function cellClick(e) { >>> var fc = e.target; >>> if (/input|select/i.test(fc.tagName)) { >>> window.alert(fc.type + " - " + fc.nodeName >>> + " - " + fc.value + " - " >>> + fc.nodeType); >>> } >>> } >> >> Not only as insufficient as your first approach (see my other follow-up), > > The OP's putclick() function didn't seem to take care of the select's > options. She just added new selects with the DOMcreasel() function. > >> but even more inefficient and error-prone. If you are using a regular >> expression, you need to anchor it to prevent false positives, at least >> /^(input|select)$/i. > > More efficient, but unnecessary for the test case. Why do you always > repeat it? You are not making sense. >> But you can do without such an expensive RegExp here. > > Expensive for modern JavaScript Engines? Nah. A conforming implementation of ECMAScript Edition 5 and later is required to create a new RegExp instance “each time the [/RegularExpressionLiteral/] is evaluated”, and “[t]wo regular expression literals in a program evaluate to regular expression objects that never compare as === to each other even if the two literals’ contents are identical.” (§ 7.8.5). IOW, any optimization is expressly forbidden there. And if you want to be backwards-compatible, you cannot use non-capturing parentheses for the anchored alternation, so each time the match is performed memory must be allocated for the backreference. Add to that the additional runtime for the matcher by comparison to simple string comparison. Besides, it is a misconception to assume that because there are “modern JavaScript engines” the algorithms underlying one’s ECMAScript-based script code would not need to be efficient. Because one cannot know in advance all runtime environments one’s code will be exposed to. >> Finally, the “input” appears to be coming from your imagination only; >> read again. > > You should read again as you have forgotten the HTML table in the OP's > code: > > | > | The OP is evidentially not interested in the values of these controls: Both the Subject header field value and their posting reads “Retrieve a *select* from a table cell” (emphasis by me). -- PointedEars FAQ: | SVN: Twitter: @PointedEars2 | ES Matrix: Please do not cc me. / Bitte keine Kopien per E-Mail.