function getType(variable) { if (obj === null) return String(variable); return typeof variable === ‘object‘ ? Object.prototype.toString.call(variable).replace(‘[object ‘, ‘‘).replace(‘]‘, ‘‘).toLowerCase() : typeof variable; } // 调用 getType(null); // -> null getType(undefined); // -> undefined getType({}); // -> object getType([]); // -> array getType(123); // -> number getType(true); // -> boolean getType(‘123‘); // -> string getType(/123/); // -> regexp getType(new Date()); // -> date
原文:https://www.cnblogs.com/zhangshilei/p/12194023.html