判断一个变量是否为函数类型
(function() {
let isFunction = function(arg) {
return typeof arg === 'function' || Object.prototype.toString.call(arg) === '[object Function]';
}
// 暴露给window 可以在全局中调用
window.isFunction = isFunction;
})();
测试
let fn = function() {};
let notFn = 1;
let obj = {};
console.log(isFunction(fn));
console.log(isFunction(notFn));
console.log(isFunction(obj));