A quick way to check if an object is a function...
Syntax
The .isFunction property is added to all objects, but only returns true on functions.
var returnValue = obj.isFunction;
Return value
Value
Type
Notes
API Version
true
Boolean
The object is a function
1.0
false
Boolean
The object is not a function
1.0
Examples
Pre-check that a value is not null before using .isFunction...
var val = null;
if (val.isFunction) { // Reference Error (null.isFunction not defined)
}
if (val && val.isFunction) { // false
// val is a function
}
// alternate approach using typeOf()
if (typeOf(val) == "function") { // false
// val is a function
}
classOf() — Returns the name of the class (constructor) used to create an object...
object.isFunction — A quick way to check if an object is a function...
typeOf() — Returns a more accurate object type name than Javascript's native "typeof https://developer.mozilla.org/en-US/docs/JavaScript/Reference/Operators/typeof" operator...
object.isArray — A quick way to check if an object is an array...