手写函数isFunction

判断一个变量是否为函数类型

(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));
上一篇:2021-03-15


下一篇:刚摆完界面,写一段rust调剂一下