判断一个变量是否是函数

Suppose I have any variable, which is defined as follows:

var a = function() {/* Statements */};

I want a function which checks if the type of the variable is function-like. i.e. :

function foo(v) {if (v is function type?) {/* do something */}};
foo(a);

How can I check if the variable a is of type Function in the way defined above?

One

Object.prototype.toString.call(fn)==='[object Function]'

Two

typeof fn === "function"

你可能感兴趣的:(判断一个变量是否是函数)