[JavaScript] javascript检测对象的类型 →→→→→进入此内容的聊天室

来自 , 2021-02-15, 写在 JavaScript, 查看 159 次.
URL http://www.code666.cn/view/c39b9a47
  1. /*
  2. 'typeof' and 'instanceof' isn't a reliable method to find
  3. out the object class, so this is a function that does this in a more trustable way.
  4. */
  5.  
  6. function is(type, obj) {
  7.     var clazz = Object.prototype.toString.call(obj).slice(8, -1);
  8.     return obj !== undefined && obj !== null && clazz === type;
  9. }
  10.  
  11. is('String', 'test'); // true
  12. is('String', new String('test')); // true
  13. //javascript/5315

回复 "javascript检测对象的类型"

这儿你可以回复上面这条便签

captcha