Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.javascript > #13219

Re: Finding the V offset of an element

Path csiph.com!usenet.pasdenom.info!weretis.net!feeder4.news.weretis.net!newsfeed.straub-nv.de!noris.net!newsfeed.arcor.de!newsspool1.arcor-online.net!news.arcor.de.POSTED!not-for-mail
Content-Type text/plain; charset="UTF-8"
Message-ID <1398495.AFRqVoOGUt@PointedEars.de> (permalink)
From Thomas 'PointedEars' Lahn <PointedEars@web.de>
Reply-To Thomas 'PointedEars' Lahn <cljs@PointedEars.de>
Organization PointedEars Software (PES)
Date Wed, 04 Apr 2012 22:28:51 +0200
User-Agent KNode/4.4.11
Content-Transfer-Encoding 8Bit
Subject Re: Finding the V offset of an element
Newsgroups comp.lang.javascript
References <jlgbcm$eti$1@dont-email.me> <jlgcp0$kss$1@dont-email.me> <tlgon71ol1nd21v94gcss1osimv21olv7k@4ax.com> <e9628c81-92bb-4efe-b3b2-5fcadddeb5c3@b14g2000vbz.googlegroups.com>
Followup-To comp.lang.javascript
MIME-Version 1.0
Lines 93
NNTP-Posting-Date 04 Apr 2012 22:28:51 CEST
NNTP-Posting-Host 951d4c26.newsspool1.arcor-online.net
X-Trace DXC=kERYP8LMf]`PXlQ;h]GTMdic==]BZ:afn4Fo<]lROoRa<`=YMgDjhgb:lDn3Y]T[_eDZm8W4\YJNlJ`:FmdeL>K`6JDa4d]ka`eSGeaDLMh6Ci
X-Complaints-To usenet-abuse@arcor.de
Xref csiph.com comp.lang.javascript:13219

Followups directed to: comp.lang.javascript

Show key headers only | View raw


Richard Cornford wrote:

> Hans-Georg Michna wrote:
>> On Tue, 3 Apr 2012 22:18:28 -0430, Leonardo Azpurua wrote:
>>> s.indexOf("TableRow") < 0 &&
>>> s.indexOf("Form") < 0) n += elt.offsetTop;
>>
>> Just a little remark on the sidelines: IE8 and older cannot do
>> s.indexOf(...) .
>>
>> You may want to use something like this instead:
>>
>> function indexOf(s, a) {
>> var index = -1;
>> for (var i = 0; i < a.length; i++) {
>> if (a[i] === s) {
>> index = i;
>> break;
>> }
>> }
>> return index;
>>
>> }
> 
> Array.prototype.indexOf -  is not built-in prior to ES5 but -
> String.prototype.indexOf - has been around for longer than I have been
> using javascript, […]

There is no "javascript", there are ECMAScript implementations.

String.protototype.indexOf(string) has been introduced with JavaScript 1.0, 
JScript 1.0, and ECMAScript Ed. 1 and is probably supported by all 
implementations that are based on the latter and its successors (tests are 
pending but no surprises are expected there).


Array.prototype.indexOf(…) is supported since JScript 9.0 in Internet 
Explorer 9.0.8112.16421 for Windows 7 Pro 32-bit SP1 in Standards Mode.  It 
passed all test cases in (Mozilla) JavaScript 1.6 in Firefox 1.5.0.12 for 
Windows, and since JavaScript 1.8 (Firefox 3.0.19 for Windows), but 
JavaScript 1.7 in Firefox 2.0 for Windows failed test case #10. 

It is supported in Google V8 JavaScript since at least version 3.7.12.12 in 
Chrome 17.0.963.78 (Developer Build 125577 Linux), Apple JavaScriptCore 
since at least version 531.22.7 in Safari for Windows 4.0.5 (531.22.7), 
Opera ECMAScript 9.52 in Opera 9.52.10108 for Windows, and KDE JavaScript 
since at least version 4.6.5 in Konqueror 4.6.5.  Surprisingly, Opera 
ECMAScript 8.0 in Opera 8.0.7561 for Windows failed all test cases except 
#12.

As such, Array.prototype.indexOf(…) is a feature that cannot be considered 
safe for use for the time being, but it is easily emulated.

The test cases were:

 (1) jsx.object.isNativeMethod(jsx.global, "Array", "prototype", "indexOf")
 (2) var i = new Array().indexOf("foo");
     typeof i == "number" && i == -1
 (3) var i = new Array("2", 2).indexOf(2);
     typeof i == "number" && i == 1
 (4) var i = new Array("foo", "foo").indexOf("foo", 1);
     typeof i == "number" && i == 1
 (5) var i = new Array("foo", "foo").indexOf("foo", "1");
     typeof i == "number" && i == 1
 (6) var i = new Array("foo").indexOf("bar")
     typeof i == "number" && i == -1
 (7) var i = new Array("foo", "bar").indexOf("foo", 1);
     typeof i == "number" && i == -1
 (8) var i = new Array("foo", "bar").indexOf("foo", "1");
     typeof i == "number" && i == -1
 (9) var i = new Array("foo", "foo").indexOf("foo", -2);
     typeof i == "number" && i == 0
(10) var i = new Array("foo").indexOf("foo", 1);
     typeof i == "number" && i == -1
(11) var len = Array.prototype.indexOf.length;
     typeof len == "number" && len == 1
(12) var o = new Object();
     o.indexOf = Array.prototype.indexOf;
     o[0] = 42;
     o[1] = "42";
     o[2] = 42;
     o.length = 3;
     o.indexOf(42) == 0


HTH

PointedEars
-- 
Use any version of Microsoft Frontpage to create your site.
(This won't prevent people from viewing your source, but no one
will want to steal it.)
  -- from <http://www.vortex-webdesign.com/help/hidesource.htm> (404-comp.)

Back to comp.lang.javascript | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread


Thread

Finding the V offset of an element "Leonardo Azpurua" <leonardo@exmvps.org> - 2012-04-03 21:54 -0430
  Re: Finding the V offset of an element "Leonardo Azpurua" <leonardo@exmvps.org> - 2012-04-03 22:18 -0430
    Re: Finding the V offset of an element "Leonardo Azpurua" <leonardo@exmvps.org> - 2012-04-03 22:34 -0430
    Re: Finding the V offset of an element Hans-Georg Michna <hans-georgNoEmailPlease@michna.com> - 2012-04-04 14:49 +0200
      Re: Finding the V offset of an element "Leonardo Azpurua" <leonardo@exmvps.org> - 2012-04-04 10:28 -0430
        Re: Finding the V offset of an element Hans-Georg Michna <hans-georgNoEmailPlease@michna.com> - 2012-04-05 09:12 +0200
      Re: Finding the V offset of an element Eric Bednarz <bednarz@fahr-zur-hoelle.org> - 2012-04-04 20:28 +0200
        Re: Finding the V offset of an element Hans-Georg Michna <hans-georgNoEmailPlease@michna.com> - 2012-04-05 09:13 +0200
      Re: Finding the V offset of an element Richard Cornford <Richard@litotes.demon.co.uk> - 2012-04-04 07:05 -0700
        Re: Finding the V offset of an element Thomas 'PointedEars' Lahn <PointedEars@web.de> - 2012-04-04 22:28 +0200
          Re: Finding the V offset of an element Eric Bednarz <bednarz@fahr-zur-hoelle.org> - 2012-04-05 00:44 +0200
            Re: Finding the V offset of an element Thomas 'PointedEars' Lahn <PointedEars@web.de> - 2012-04-05 05:50 +0200
              Re: Finding the V offset of an element Eric Bednarz <bednarz@fahr-zur-hoelle.org> - 2012-04-05 11:22 +0200
                Re: Finding the V offset of an element Thomas 'PointedEars' Lahn <PointedEars@web.de> - 2012-04-05 13:21 +0200
          Re: Finding the V offset of an element Richard Cornford <Richard@litotes.demon.co.uk> - 2012-04-05 04:35 -0700
            Re: Finding the V offset of an element Thomas 'PointedEars' Lahn <PointedEars@web.de> - 2012-04-05 14:02 +0200
              Re: Finding the V offset of an element Richard Cornford <Richard@litotes.demon.co.uk> - 2012-04-10 09:32 -0700
          Re: Finding the V offset of an element John G Harris <john@nospam.demon.co.uk> - 2012-04-05 14:54 +0100
            Re: Finding the V offset of an element Gene Wirchenko <genew@ocis.net> - 2012-04-05 08:37 -0700
  Re: Finding the V offset of an element Richard Cornford <Richard@litotes.demon.co.uk> - 2012-04-04 04:57 -0700
    Re: Finding the V offset of an element Hans-Georg Michna <hans-georgNoEmailPlease@michna.com> - 2012-04-05 09:16 +0200
      Re: Finding the V offset of an element "Richard Cornford" <Richard@litotes.demon.co.uk> - 2012-04-05 09:38 +0100
        Re: Finding the V offset of an element Hans-Georg Michna <hans-georgNoEmailPlease@michna.com> - 2012-04-08 18:27 +0200
  Re: Finding the V offset of an element Dr J R Stockton <reply1214@merlyn.demon.co.uk.not.invalid> - 2012-04-06 21:52 +0100
    Re: Finding the V offset of an element "Leonardo Azpurua" <leonardo@exmvps.org> - 2012-04-07 11:18 -0430

csiph-web