Suppose we have any variable, which is defined as follows:
We want a function which checks if the type of the variable is function-like. i.e. :
How can we check if the variable 'a' is of type function in the way defined above?
- Sure underscore's way is more efficient, but the best way to check, when efficiency isn't an issue, is written on underscore's page linked by @Paul Rosania.
- Inspired by underscore, the final isFunction function is as follows:
@grandecomplex: There's a fair amount of verbosity to our solution. It would be much clearer if written like this:
If we use jquery we can use the isFunction:
Try instanceof: It seems that all functions inherit from the "Function" class: