Re: When is a function not a function?



Randy Webb wrote:
Richard Cornford said the following on 10/13/2007 10:28 PM:
<dhtmlkitchen@xxxxxxxxx> wrote:
On Oct 13, 2:41 am, Thomas 'PointedEars' Lahn wrote:
dhtmlkitc...@xxxxxxxxx wrote:
<snip>
It'snotsafe, but it's indicative of the problem of
typechecking in js.

No, it is indicative of the bad quality of the calling script,
and ultimately of the bad quality of the called script. As
Richard said, one should never get into a position where a
test of that form would be necessary.

how can you know if it's a function?

First define what you mean by "a function".

typeof fn? nope, not in safari.

Are you certain? Is it really the case that objects that
return 'function' from a typeof operation cannot be
called? Or are you just not expecting them to be callable?
Have you actually tried calling the objects that safari
asserts are functions?

Can I ask you to first define what you mean by "called"
or "callable"?

No more than sticking an ArgumentsList after a reference to the object (the 'call operator', with or without arguments). That is what I would consider calling an object, and to be callable that abject should not throw an exception as a direct result of its being called (though it may still throw an exception in response to its arguments'' values, as that would be behaviour passed the point of calling it and so unrelated to its callability).

document.links, document.getElementsByTagName("blah")

Safari thinks they implement call, which is what typeof
checks for.
<snip>

One of the consequences of using imprecise terminology is that
when you say "call" nobody knows whether you mean [[Call]] or Function,.prototype.call. It is the implementing of the internal [[Call]] method that typeof should be interested in, though not necessarily for host objects. NodeLists and HTMLCollection
interface implementing objects would be host obejcts.

So document.images should be a Host Object?

It must be a host object, as it is provided by the host's object model.

Safari3/Win reports typeof(document.images) as 'function'.

Apparently.

All other Windows based browsers I have report it as 'object'.

Maybe, but that is neither necessarily true of windows based browsers nor historically common on Mac browsers. Even Mac IE 5 would report 'function' in this context, and on Windows you only have to go back a few Opera versions to see the same there.

(Incidentally, I will be replying to your e-mail soonish, but I will have to do some research first so probably not for a day or two.)

Richard.

.



Relevant Pages

  • Re: Are there dreams you still believe?
    ... Obviously Richard, your hatred has blinded you to who is doing the ... is the person doing the calling out. ... Hateful Richard. ... Ever consider that mebbe, just mebbe you are the one who is acting in a ...
    (rec.music.gdead)
  • Re: Kensington runestone Vegetation)in the Scandinavian press
    ... >> Alaca created ... >>> Calling someone wrong is very easy. ... > But, although I like the character, I am not Richard. ... well richard is especially whipped. ...
    (sci.archaeology)
  • Re: More sad news from the opera world
    ... name calling and other assorted crap. ... Richard ... Prev by Date: ...
    (rec.music.opera)
  • Re: When is a function not a function?
    ... As Richard said, ... Is it really the case that objects that return 'function' from a typeof operation cannot be called? ... Have you actually tried calling the objects that safari asserts are functions? ... It is the implementing of the internal ] method that typeof should be interested in, though not necessarily for host objects. ...
    (comp.lang.javascript)
  • Re: hmmm
    ... Whatever you say Alexander, Richard, Winterbourne or whatever you're ... calling yourself nowadays. ...
    (uk.rec.subterranea)

Loading