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 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> References: <16yzpmtikrwk0$.1schjt968gcx$.dlg@40tude.net> <1791221.7QuZn8ShVB@PointedEars.de> <14ignx5l3afjk.j09ycbpj6e7h.dlg@40tude.net> <1695306.Qhb0f9IOXP@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 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 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: | SVN: Twitter: @PointedEars2 | ES Matrix: Please do not Cc: me. / Bitte keine Kopien per E-Mail.