Possible Duplicate:
How can I check if a javascript variable is function type?
How i check if a variable is a function
for Array exist Array.isArray()
but Function.isFunction
dos'nt exist
Possible Duplicate:
How can I check if a javascript variable is function type?
How i check if a variable is a function
for Array exist Array.isArray()
but Function.isFunction
dos'nt exist
You can use the instanceof
operator.
var fn = function() {};
var result = fn instanceof Function; // result will be true
It also respects prototypal inheritance.
Underscore.js is a library that has a lot of useful helpers, like the one you're looking for.
_ = require('underscore');
var aFunction = function() { };
var notFunction = 'Not a function';
_.isFunction(aFunction); // true
_.isFunction(notFunction); // false
var fn = function() {},
toString = Object.prototype.toString;
first way:
if( toString.call( function(){} ) === '[object Function]' ) {
//if is Function do something...
}
second way:
if( fn.constructor.name = 'Function' ) {
//if is Function do something...
}
Hope it helps cheers:)!