Re: When is a function not a function?
- From: "Richard Cornford" <Richard@xxxxxxxxxxxxxxxxxxx>
- Date: Mon, 26 Nov 2007 23:12:09 -0000
Matt Kruse wrote:
On Nov 26, 1:54 pm, Richard Cornford wrote:You might reasonably say that if - typeof x - was 'function'
then it would be safe to call the object, and be correct in
all the environments that I have ever encountered.
Unfortunately, in Firefox:
var o = document.createElement("object");
alert(typeof o); // "function"
o(); // ERROR
You are making a surprisingly obvious mistake here. You are assuming that because calling a function results in an exception being thrown then that means that the function/object is not callable. When you think about that it is pretty obvious that such a conclusion is not valid.
In Firefox, when you call an object that is not callable the exception thrown is "o is not a function", but the exception here is "Component is not available", so you cannot prove that the object is not callable, only that calling it throws an exception. It could be that if and when the "Component" (whatever that may be in this case) was available you could happily call the function/object without an exception being thrown.
The bottom line is that an object's being callable is no guarantee that calling will be an error free operation.
<snip>
This is actually the origin of the above case that
fails in FF.
So this is not your mistake, you just didn't think about it enough to see who was being fooled here.
Richard.
.
- Follow-Ups:
- Re: When is a function not a function?
- From: Matt Kruse
- Re: When is a function not a function?
- References:
- Re: When is a function not a function?
- From: Matt Kruse
- Re: When is a function not a function?
- From: Richard Cornford
- Re: When is a function not a function?
- From: Matt Kruse
- Re: When is a function not a function?
- Prev by Date: Re: Javascript onChange if field1 = xxx then change field2 = yyy
- Next by Date: Re: FAQ Topic - Why is my AJAX page not updated properly when using an HTTP GET request in Internet Explorer? (2007-11-23)
- 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
|