javascript检测对象的类型
/* 'typeof' and 'instanceof' isn't a reliable method to find out the object class, so this is a function that does this in a more trustable way. */ function is(type, obj) { var clazz = Object.prototype.toString.call(obj).slice(8, -1); return obj !== undefined && obj !== null && clazz === type; } is('String', 'test'); // true is('String', new String('test')); // true