美文网首页
函数式编程——判断类型

函数式编程——判断类型

作者: _____西班木有蛀牙 | 来源:发表于2018-05-10 09:34 被阅读16次
    // 返回一个判断类型的函数
    function isType(Type) {
        return function (val) {
            return Object.prototype.toString.call(val) === `[object ${Type}]`
        }
    }
    isFunction = isType('Function');
    isString = isType('String');
    isDate = isType('Date');
    isNumber = isType('Number'); // NaN 也是number
    isObject = isType('Object');
    isUndefine = isType('Undefined');
    isNull = isType('Null')
    
    image.png

    相关文章

      网友评论

          本文标题:函数式编程——判断类型

          本文链接:https://www.haomeiwen.com/subject/vuzarftx.html