判斷數據類型

const isType=function(type){
    return function(obj){
        return Object.prototype.toString.call(obj)===`[object ${type}]`;
    }
}
const isString=isType('String');
const isArray=isType('Array');
const isNumber=isType('Number');

isString('s');    //true
isArray([1,2]);    //true
isNumber(1);        //true

 

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章