Re: isFunction (Code Worth Recommending Project)



On Dec 8, 9:33 am, Thomas 'PointedEars' Lahn <PointedE...@xxxxxx>
wrote:
David Mark wrote:
I see the "When is a function not a function" thread has flared up
again.

This is what I use to test parameters that can be Functions or
Objects. It does return the expected result for callable host objects
(at least the ones I tested.) None of the functions it supports are
expected to receive those as parameters. The second part of the test
is a little ambiguous in this regard (for browsers that do not support
call), so it is best to exclude callable host objects as a rule.

var isFunction = function(o) {
return typeof(o) == 'function' && (!Function.prototype.call ||
typeof(o.call) == 'function');
};

isFunction() will return `false' where Function.prototype.call is not
supported and the object has no `call' property, even though the argument
referred to a Function object. That is the case in JavaScript before

If it is a Function then the first part of the conjunction is true.
The second part will also be true as !Function.prototype.call will
evaluate to true when call is not supported. So just what are you
talking about?

[snip]


The argument may be an unqualified reference in which case calling this
testing method fails if the identifier of that reference was not defined before.

You aren't allowed to pass anything but Function objects or Object
objects. Those are the rules as documented. Results are not defined
for anything else.


There is no point in assigning a function object created by a function
expression in the initialization of a variable instead of a simple function
declaration, unless that code is part of a conditional execution block.

The reason it is written like that is it was originally assigned as a
method of an object.


`typeof' is an operator, not a method, and should be written accordingly.

That is just my personal style. I've always written it that way and I
think it is easier to read.
.



Relevant Pages

  • Re: isFunction (Code Worth Recommending Project)
    ... This is what I use to test parameters that can be Functions or ... is a little ambiguous in this regard (for browsers that do not support ... so it is best to exclude callable host objects as a rule. ... testing method fails if the identifier of that reference was not defined before. ...
    (comp.lang.javascript)
  • Re: isFunction (Code Worth Recommending Project)
    ... This is what I use to test parameters that can be ... this regard (for browsers that do not support call), ... best to exclude callable host objects as a rule. ... David, then why isn't the function that simple? ...
    (comp.lang.javascript)