var typeOf = function (o){
var s = Object.prototype.toString.call(o);
return s.match(/\[object (.*?)\]/)[1].toLowerCase();
};
typeOf({}); // "object"
typeOf([]); // "array"
typeOf(5); // "number"
typeOf(null); // "null"
typeOf(); // "undefined"
typeOf(/abcd/); // "regex"
typeOf(new Date()); // "date"
沒有留言:
張貼留言