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


Groups > comp.lang.javascript > #19261

Re: trying to call onclick with document.getElement() - document.getElement() returns null

Message-ID <7595870.kvP59otsHy@PointedEars.de> (permalink)
From Thomas 'PointedEars' Lahn <PointedEars@web.de>
Organization PointedEars Software (PES)
Date 2013-04-13 21:31 +0200
Subject Re: trying to call onclick with document.getElement() - document.getElement() returns null
Newsgroups comp.lang.javascript
References (3 earlier) <kkb7dq$ggn$1@portraits.wsisiz.edu.pl> <2061545.QaVc4i2NtW@PointedEars.de> <kkbe2r$ioc$1@portraits.wsisiz.edu.pl> <1693880.XzSgBGLykG@PointedEars.de> <kkcam8$smf$1@portraits.wsisiz.edu.pl>

Show all headers | View raw


Cezary Tomczyk wrote:

> W dniu 2013-04-13 13:26, Thomas 'PointedEars' Lahn pisze:
>> Cezary Tomczyk wrote:
>>> W dniu 2013-04-13 11:45, Thomas 'PointedEars' Lahn pisze:
>>>> Cezary Tomczyk wrote:
>>>>> W dniu 2013-04-13 10:29, Thomas 'PointedEars' Lahn pisze:
>>>>>> Mikael Andersson wrote:
>>>>> [...]
>>>>>>>>            if (window.XMLHttpRequest) {
>>>>>>
>>>>>> Insufficient and error-prone, see isHostMethod().
>>>>> [...]
>>>>>
>>>>> Just our of curiosity: in which environment / scenario this will not
>>>>> be properly evaluated?
>>>>
>>>> Where “XMLHttpRequest” is not a property of the object referred to by
>>>> “window”, but of another object in the scope chain.
>>>
>>> Even then isHostMethod will return true,
>>
>> No, it will return “false”.  The point is _not_ that you should call
> 
> Can you provide me an example of when this may occur?

No, you just need to read more carefully.  Hopefully a *working* 
implementation of isHostMethod() will return a false-value if the property 
in question does not exist.
 
>>    isHostMethod(window, "XMLHttpRequest")
>>
>> or
>>
>>    jsx.object.isHostMethod(jsx.global, "window", "XMLHttpRequest")
>>
>> instead – that would be equally wrong –, but that isHostMethod()
>> implements the *algorithm* to detect host methods *safely*, without
>> implicit type conversion.
> 
> I know both of methods, but sometimes simple statement "if
> (window.XMLHttpRequest)" just do the job and I never had any problems
> with that.

You were asking about possible scenarios; I have provided you with them.
You should not think that “it works” justifies approaches that are 
objectively unwise at best.  See also: Argumentum ad crumenam.

-- 
PointedEars

Twitter: @PointedEars2
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

trying to call onclick with document.getElement() - document.getElement() returns null jorythompson@gmail.com - 2013-04-12 10:45 -0700
  Re: trying to call onclick with document.getElement() - document.getElement() returns null Jordan Thompson <jorythompson@gmail.com> - 2013-04-12 11:01 -0700
  Re: trying to call onclick with document.getElement() - document.getElement() returns null Mikael Andersson <qubex2@gmail.com> - 2013-04-12 21:31 +0200
    Re: trying to call onclick with document.getElement() - document.getElement() returns null Thomas 'PointedEars' Lahn <PointedEars@web.de> - 2013-04-13 10:29 +0200
      Re: trying to call onclick with document.getElement() - document.getElement() returns null Cezary Tomczyk <cezary.tomczyk@gmail.com> - 2013-04-13 11:10 +0200
        Re: trying to call onclick with document.getElement() - document.getElement() returns null Thomas 'PointedEars' Lahn <PointedEars@web.de> - 2013-04-13 11:45 +0200
          Re: trying to call onclick with document.getElement() - document.getElement() returns null Cezary Tomczyk <cezary.tomczyk@gmail.com> - 2013-04-13 13:04 +0200
            Re: trying to call onclick with document.getElement() - document.getElement() returns null Thomas 'PointedEars' Lahn <PointedEars@web.de> - 2013-04-13 13:26 +0200
              Re: trying to call onclick with document.getElement() - document.getElement() returns null Cezary Tomczyk <cezary.tomczyk@gmail.com> - 2013-04-13 21:12 +0200
                Re: trying to call onclick with document.getElement() - document.getElement() returns null Thomas 'PointedEars' Lahn <PointedEars@web.de> - 2013-04-13 21:31 +0200
                Re: trying to call onclick with document.getElement() - document.getElement() returns null Cezary Tomczyk <cezary.tomczyk@gmail.com> - 2013-04-16 20:01 +0200
                Re: trying to call onclick with document.getElement() - document.getElement() returns null Thomas 'PointedEars' Lahn <PointedEars@web.de> - 2013-04-16 23:13 +0200
      Re: trying to call onclick with document.getElement() - document.getElement() returns null Mikael Andersson <qubex2@gmail.com> - 2013-04-13 18:35 +0200

csiph-web