Blackbaby 发表于 2013-1-29 09:13:10

JavaScript:The Class of an Object

function is(type, obj) {   var clas = Object.prototype.toString.call(obj).slice(8, -1);   return obj !== undefined && obj !== null && clas === type; }is('String', 'test'); // true is('String', new String('test')); // true  
 
   In the above example, Object.prototype.toString gets called with the value of this being set to the object whose [] value should be retrieved.
页: [1]
查看完整版本: JavaScript:The Class of an Object