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


Groups > comp.lang.javascript > #25919

Re: eventDispath how that work

Path csiph.com!v102.xanadu-bbs.net!xanadu-bbs.net!feeder.erje.net!eu.feeder.erje.net!weretis.net!feeder1.news.weretis.net!news.solani.org!.POSTED!not-for-mail
From Thomas 'PointedEars' Lahn <PointedEars@web.de>
Newsgroups comp.lang.javascript
Subject Re: eventDispath how that work
Date Thu, 16 Oct 2014 18:11:55 +0200
Organization PointedEars Software (PES)
Lines 48
Message-ID <2222130.ANbu49Xpvc@PointedEars.de> (permalink)
References <m1jblb$4a7$1@shakotay.alphanet.ch> <16yzpmtikrwk0$.1schjt968gcx$.dlg@40tude.net> <1791221.7QuZn8ShVB@PointedEars.de> <14ignx5l3afjk.j09ycbpj6e7h.dlg@40tude.net> <1695306.Qhb0f9IOXP@PointedEars.de>
Reply-To Thomas 'PointedEars' Lahn <cljs@PointedEars.de>
Mime-Version 1.0
Content-Type text/plain; charset="UTF-8"
Content-Transfer-Encoding 8Bit
X-Trace solani.org 1413475918 23494 eJwFwYEBwDAEBMCViEeMU+T3H6F3bqExifCA04k6c1N0aYOv1IA+WbE9wsxVXVDTh3Ltvf4BDwURAw== (16 Oct 2014 16:11:58 GMT)
X-Complaints-To abuse@news.solani.org
NNTP-Posting-Date Thu, 16 Oct 2014 16:11:58 +0000 (UTC)
User-Agent KNode/4.14.1
X-User-ID eJwNxtsBADEEBMCWCOtRjgT9l3A3XwMxtudqMMViW+5iohxnOIlFJsX98h7qddIjFE6VdZMiJ7TxIuavW4M/PwMUvg==
Cancel-Lock sha1:TnZpUYrrHnNwWqd/kqLCxqiPJbc=
X-NNTP-Posting-Host eJwFwYEBwCAIA7CXVFrEc4DR/09YQvPtfeF0UJQp7+DUA4IZK2x9PGq39eIMhZ1bVehr0OAHEBYQ1A==
Xref csiph.com comp.lang.javascript:25919

Show key headers only | View raw


Thomas 'PointedEars' Lahn wrote:

> Incidentally, at work today I encountered, essentially, this piece of code
> written by someone else:
> 
>   if (window.toString.call(…) == "[object Array]") {
>     // …
>   }
> 
> (Obviously an attempt to detect whether an value would be a reference to
> an Array instance, which is in many cases a misguided one [see “duck
> typing” for details].)
> 
> It failed reproducibly in Internet Explorer 8 (with the infamous “error
> code 0”) on Windows XP¹ because there was no “window.toString”, and that
> caused *other* code (a progress indicator) to not function (a
> JScript/MSHTML peculiarity).
> 
> For now, I can see three possible explanations how this code came about
> (I will investigate this tomorrow morning):
> 
> […]
>   C. Someone thought “window” would refer to the native ECMAScript global
>      object and would therefore have a built-in “toString” method.

I must assume that this was it.  The code above failed because the *host* 
object referred to by “window” did have a built-in “toString” method that 
you could call (it returned "[object]" then), but the referred callable 
*host* object did not have a “call” method itself.

After I replaced “window” with a reference to an Object instance (here: 
dict) – a *native* object –, that part of the code worked again in IE 8:

  if (dict.toString.call(…) == "[object Array]") {
    // …
  }

Because the Object instance inherited its “toString” method from the 
*native* object referred to by “Object.prototype” which, as per 
Specification, has a “toString” method that is a Function instance – a 
*native* object.  That, in turn, inherits a “call” method from the *native* 
object referred to by “Function.prototype”.

-- 
PointedEars
FAQ: <http://PointedEars.de/faq> | SVN: <http://PointedEars.de/wsvn/>
Twitter: @PointedEars2 | ES Matrix: <http://PointedEars.de/es-matrix>
Please do not Cc: me. / Bitte keine Kopien per E-Mail.

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


Thread

eventDispath how that work Une Bévue <unbewusst.sein@fai.invalid> - 2014-10-14 16:23 +0200
  Re: eventDispath how that work JJ <jj4public@vfemail.net> - 2014-10-15 03:24 +0700
    Re: eventDispath how that work Une Bévue <unbewusst.sein@fai.invalid> - 2014-10-15 10:49 +0200
    Re: eventDispath how that work Thomas 'PointedEars' Lahn <PointedEars@web.de> - 2014-10-15 15:24 +0200
      Re: eventDispath how that work JJ <jj4public@vfemail.net> - 2014-10-16 02:10 +0700
        Re: eventDispath how that work Thomas 'PointedEars' Lahn <PointedEars@web.de> - 2014-10-15 23:02 +0200
          Re: eventDispath how that work Joao Rodrigues <groups_jr-1@yahoo.com.br> - 2014-10-15 18:59 -0300
            Re: eventDispath how that work Thomas 'PointedEars' Lahn <PointedEars@web.de> - 2014-10-16 02:48 +0200
          Re: eventDispath how that work Thomas 'PointedEars' Lahn <PointedEars@web.de> - 2014-10-16 18:11 +0200
      Re: eventDispath how that work Une Bévue <unbewusst.sein@fai.invalid> - 2014-10-15 22:06 +0200
        Re: eventDispath how that work Thomas 'PointedEars' Lahn <PointedEars@web.de> - 2014-10-15 23:39 +0200
          Re: eventDispath how that work Une Bévue <unbewusst.sein@fai.invalid> - 2014-10-16 14:26 +0200
            Re: eventDispath how that work Joao Rodrigues <groups_jr-1@yahoo.com.br> - 2014-10-16 14:39 -0300
              Re: eventDispath how that work Joao Rodrigues <groups_jr-1@yahoo.com.br> - 2014-10-16 19:44 -0300
                Re: eventDispath how that work Une Bévue <unbewusst.sein@fai.invalid> - 2014-10-17 09:00 +0200
                Re: eventDispath how that work Joao Rodrigues <groups_jr-1@yahoo.com.br> - 2014-10-17 10:16 -0300
                Re: eventDispath how that work Thomas 'PointedEars' Lahn <PointedEars@web.de> - 2014-10-17 21:40 +0200
                Re: eventDispath how that work Joao Rodrigues <groups_jr-1@yahoo.com.br> - 2014-10-17 17:03 -0300
                Re: eventDispath how that work Une Bévue <unbewusst.sein@fai.invalid> - 2014-10-18 15:46 +0200
              Re: eventDispath how that work Une Bévue <unbewusst.sein@fai.invalid> - 2014-10-17 08:26 +0200

csiph-web