判断对象是否是某个类的实例,可以用instanceof运算符,但是不推荐使用

比如var obj = new Date();

obj instanceof Date;//true

obj instanceof Object;//true

obj instanceof Array;//true

推荐使用constructor属性判断

obj.constructor == Date //true

function Test(){}

var tt = new Test();

tt.constructor == Test;//true

相关文章:

  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2022-01-30
  • 2022-12-23
  • 2021-07-06
猜你喜欢
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2021-10-16
  • 2022-12-23
  • 2022-12-23
相关资源
相似解决方案