Re: When is a function not a function?
- From: "Richard Cornford" <Richard@xxxxxxxxxxxxxxxxxxx>
- Date: Sun, 14 Oct 2007 16:18:42 +0100
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:<snip>dhtmlkitc...@xxxxxxxxx wrote:how can you know if it's a function?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.
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")<snip>
Safari thinks they implement call, which is what typeof
checks for.
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.
.
- Follow-Ups:
- Re: When is a function not a function?
- From: Randy Webb
- Re: When is a function not a function?
- References:
- Re: When is a function not a function?
- From: dhtmlkitchen@xxxxxxxxx
- Re: When is a function not a function?
- From: Thomas 'PointedEars' Lahn
- Re: When is a function not a function?
- From: dhtmlkitchen@xxxxxxxxx
- Re: When is a function not a function?
- From: Richard Cornford
- Re: When is a function not a function?
- From: Randy Webb
- Re: When is a function not a function?
- Prev by Date: Re: How to add items to an object in a for loop?
- Next by Date: Re: When is a function not a function?
- Previous by thread: Re: When is a function not a function?
- Next by thread: Re: When is a function not a function?
- Index(es):
Relevant Pages
|
Loading